Is there a destructor for Java?

前端 未结 22 1399
[愿得一人]
[愿得一人] 2020-11-22 11:47

Is there a destructor for Java? I don\'t seem to be able to find any documentation on this. If there isn\'t, how can I achieve the same effect?

To make my question m

22条回答
  •  太阳男子
    2020-11-22 12:32

    No, java.lang.Object#finalize is the closest you can get.

    However, when (and if) it is called, is not guaranteed.
    See: java.lang.Runtime#runFinalizersOnExit(boolean)

提交回复
热议问题