作者superlubu (叔叔你人真好)
看板java
标题Re: [问题] 解构的顺序
时间Sat Mar 15 19:12:02 2008
※ 引述《Robert0512 (天天冲浪三国无双)》之铭言:
: 喔喔 我是把每个的finalize()都写不同的
: 譬如C就是
: public void finalize(){
: System.out.printly("this is C");
: }
: 这样会有问题出现吗?
我做过实验,只会出现 c 的 finalize call: (JDK 1.5)
a.java:
public class a {
public a() { System.out.println("instance of class a, created."); }
protected void finalize() throws Throwable {
System.out.println("instance of class a, finalized.");
}
}
b.java:
public class b extends a {
public b() { System.out.println("instance of class b, created."); }
protected void finalize() throws Throwable {
System.out.println("instance of class b, finalized.");
}
}
c.java:
public class c extends b {
public c() { System.out.println("instance of class c, created."); }
protected void finalize() throws Throwable {
System.out.println("instance of class c, finalized.");
}
public static void main(String arg[]) throws Exception {
c obj = new c();
obj = null;
System.gc();
Thread.sleep(6000000);
}
}
结果如下:
instance of class a, created.
instance of class b, created.
instance of class c, created.
instance of class c, finalized.
--
劲过吕布的劲过相簿...
http://www.pixnet.net/superlubu
乱七八糟的,不好意思 m(_ _)m
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.103.138.188
※ 编辑: superlubu 来自: 218.103.138.188 (03/15 19:12)
1F:推 Robert0512:感谢讲解 是我弄错了一些地方 囧 03/15 19:20