Java, executing a method when object's scope ends -


I have an object with a fixed position passed to the object and this state has been temporarily replaced. is. Something like this:

  Public Obligation (MyObject obj) {obj.saveState (); Obj.changeState (...); Obj.use (); Obj.loadState (); }  

It is possible to use the scope of the object to run some code while constructing and destructing in C ++, such as << p>

  NeatManager (MyObject obj ) {Obj. Save the state (); } ~ NeatManager () {obj.loadState (); }  

and call it

  delete something (MyObject obj) {NeatManager mng (obj); Obj.changeState (); Obj.use (); }  

This simplifies the work, because the save / load is tied to the NeatManager object, is it possible to do something like this in Java? Is there any way a way to call a method, when the object goes out of the scope, which it has been declared?

There is no point in the closest possibly one attempt / ultimately block:

  try {obj.changeState (...); Obj.use (); } Finally {obj.loadState (); }  

ensures that loadState () is also called when an exception is thrown or an initial return .


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

jQuery UI: Datepicker month format -

php - multilevel menu with multilevel array -