关于System.gc()的执行?

package FinalizeTest;


public class Person {

    

    public Person(){

        System.out.println("person created");

    }


    @Override

    protected void finalize() throws Throwable {

        // TODO Auto-generated method stub

        System.out.println("gc ");

        throw new Exception("no effect");

    }

}




package FinalizeTest;


public class MainTest {


    /**

     * @param args

     */

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Person per = new Person();

        per = null;

        System.gc();

        System.out.println("hello world");


    }


}

输出为


person created

hello world

gc 

代码如上所示, 求解释为什么hello world会在gc之前输出??


元芳怎么了
浏览 640回答 4
4回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java