java finalize方法

/**
 * 
 */


/**
 * @author 
 *
 */
public class FinalizeTest {

	private boolean flag=false;
	
	public FinalizeTest(boolean flag){
		this.flag=flag;
		
	}
	public void checkIn(){
		this.flag=false;
		
	}
	protected void finalize() throws Throwable {
		
		if(flag){
			System.out.println("error ");
		}
	};
	/**
	 * @param args
	 * @throws Throwable 
	 */
	public static void main(String[] args) throws Throwable {
		FinalizeTest f=new FinalizeTest(true);
		f.checkIn();
		
		/*FinalizeTest ff=new FinalizeTest(true);
		ff.checkIn();
		ff.finalize();*/
                new FinalizeTest(true);
		System.gc();
	}

}

你可能感兴趣的:(finalize)