System.gc()为什么没有调用finalize()方法?
cc945 2005-09-19 09:42:53 //下列程序为什么没有调用finalize()?
//改 Book novel=new Book(true) 为 new Book(true) 则调用finalize(),为什么?
//咨询finalize()和System.gc()使用经验!!
class Book {
boolean checkedOut=false ;
Book(boolean checkOut) {
checkedOut = checkOut;
}
void checkIn() {
checkedOut = false;
}
public void finalize() {
if(checkedOut)
System.out.println("Error: checked out");
}
}
public class TerminationCondition {
public static void main(String[] args) {
new Book(true);
System.gc();
}
}