我是一個java的垃圾收集器部分,我寫了下面的java類,但它顯示了編譯時錯誤在eclipse編輯器本身的方法printGCStats() 選擇它正顯示出「無效」 @expected錯誤,請advse如何從這個克服...java類編譯時錯誤
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
class demoGrbage {
public static void main(String[] args) {
public void printGCStats()
{
long totalGarbageCollections = 0;
long garbageCollectionTime = 0;
for(GarbageCollectorMXBean gc :
ManagementFactory.getGarbageCollectorMXBeans()) {
long count = gc.getCollectionCount();
if(count >= 0) {
totalGarbageCollections += count;
}
long time = gc.getCollectionTime();
if(time >= 0) {
garbageCollectionTime += time;
}
}
System.out.println("Total Garbage Collections: "
+ totalGarbageCollections);
System.out.println("Total Garbage Collection Time (ms): "
+ garbageCollectionTime);
}
}
}