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) {
No, there's nothing like that. The closest you've got is try/finally.
In C# there's the using
statement, which executes a Dispose
method at the end:
using (Stream x = ...)
{
} // x.Dispose() is called here, in a finally block
There's a possibility that Java 7 will gain something a bit like this, but I don't think anything's been set in stone yet.