Simon Wistow wrote:
because that doesn't make sense. So what you have to do is
Foo foo;
try {
foo = FooFactory.getFoo();
runBar(foo);
} catch (SomeCommonException e) {
System.err.println("Got an exception: "+e);
} finally {
FooFactory.release(foo);
}
public void runBar(final Foo foo) {
Bar.doSomething(new BarRunner() {
public void quux() {
foo.execute();
}
});
}
And people wonder why Java has a reputation as being verbose?
And it a *lot* more verbose if "FooFactory.release(foo);" has a chance
of throwing an exception... say, if it were a JDBC "Connection.close()"
method call.