Re: [問題] 解構的順序
※ 引述《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)
推
03/15 19:20, , 1F
03/15 19:20, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
2
3
以下文章回應了本文:
問題
1
1
完整討論串 (本文為第 4 之 8 篇):
問題
1
1
問題
1
1
問題
1
1
問題
1
1
問題
2
3
問題
1
4