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之前输出??
相关分类