Java開発でfinalize()を実装するプログラム

コード下記:
public class FinalCheck {
public static void main(String[] args){
Booksell novels = new Booksell(true,"novels");
novels.checkIn();
novels = null;
new Booksell(true,"null");
Booksell zazhi = new Booksell(true,"zazhi");
System.gc();
}
}
class Booksell{
boolean checkedflag = false;
String name="";
Booksell(boolean checkout,String name){
this.checkedflag = checkout;
this.name = name;
}
void checkIn(){
System.out.println(name+" checkIn");
checkedflag = false;
}

protected void finalize(){
System.out.println(name+" finalize is working “);
if(checkedflag){
System.out.println(name+"エラー: check out");
}
}
}

Java

Posted by arkgame