If I have
public class Foo {
private boolean finalized = false;
public void foo() {
if (finalized)
throw new IllegalStateException("finalize() has been called.");
}
@Override public void finalize() {
super.finalize();
finalized = true;
}
}
Is it guaranteed, even in the face of multiple threads, assuming only the GC will call finalize()
, that the IllegalStateException
will never be thrown?
I know that in the face of a finalize()
method that causes the object to be not garbage-collectable, the object won't be garbage collected and other methods might be called. But this finalize()
doesn't do that. Is there still a possibility of foo()
being called after finalize()
?