How do you write a deconstructor in Java?

后端 未结 7 2101
萌比男神i
萌比男神i 2020-12-20 08:17

I came across this question and am looking for some ideas?

7条回答
  •  Happy的楠姐
    2020-12-20 08:34

    Java is garbage-collected, so there is no way to tell when your destructor would be called (when your object will be garbage-collected).

    There is a finalize (inherited) method but you can't rely on that for the exact reasons above (you can't predict when -and if- it will be called).

提交回复
热议问题