调用了System.gc()可finalize()怎么还无法执行
附代码如下
public class Tank {
Tank(){
full=true;
System.out.println("Tank is created.");
}
public void get(){
System.out.println("get() is called...");
full=false;
}
public void put(){
System.out.println("put() is called...");
full=true;
}
public void finalize(){
System.out.println("hello");
if(full)
{
System.out.println("Error:The tank is full.");
}
else
{
System.out.println("Tank is cleaned.");
}
}
/**
* @param args
*/
public static void main(String[] args) {
Tank t=new Tank();
t.get();
t.put();
//?此处如果不对t.finalize()进行显式调用,那么finalize()不会执行?
System.runFinalization();
t.finalize();
System.gc();
}
private boolean full=false;
}