How do you write a deconstructor in Java?

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

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

7条回答
  •  眼角桃花
    2020-12-20 08:57

    You do not need (nor should you try to use) destructors - or what they are called in Java: "Finalizers".

    The VM specification does allow for VM implementations to never call them. So they are not reliable for resource releases and the like. Generally speaking the code in the finalize() method of any object can be called by the VM before the object is garbage collected, but as this is not mandatory, you should avoid it.

提交回复
热议问题