我得到一个getInstance();找不到符号

时间:2015-07-13 06:46:36

标签: java

我收到错误。 getInstance()是否需要导入?

public class GarbageCollector
{
    public static void main(String args[])
    {
        Runtime runtime = Runtime.getInstance();
        String s ;
        System.out.println(runtime.totalMemory()); // total memory required
        System.out.println(runtime.freeMemory()); // memory freed
        for(int i=0;i<1000;i++)
            s = new String("");
        System.out.println(runtime.freeMemory()); // memory after object"s" 
                                                    //creation                               
        runtime.gc();

        System.out.println(runtime.freeMemory()); // memory after method call
    }
}

1 个答案:

答案 0 :(得分:0)

Runtime类没有getInstance()方法。

Runtime runtime = Runtime.getInstance();

应该是

Runtime runtime = Runtime.getRuntime();