Java, executing a method when object's scope ends

后端 未结 5 1248
庸人自扰
庸人自扰 2021-02-12 20:48

I\'ve an object with a certain state. The object is passed around and it\'s state is temporarly altered. Something like:

public void doSomething(MyObject obj) {
         


        
5条回答
  •  死守一世寂寞
    2021-02-12 21:15

    As an additional note, don't be tempted to use the Object.finalize() method, which runs when an object is GC'd, as you have no control over when the object is collected.

提交回复
热议问题