Hacker News new | ask | show | jobs
by mynameishere 5521 days ago
I was thinking the same thing, but replace your finally block with,

  Util.dispose(x,y);
...and let that handle all the possible issues.
1 comments

I've taken Groovy's with... syntax and built utils that are ie:

public void withConnection(Callback<Connection> callback) { Connection connection = createConnection(); try { callback.call(connection); } finally { connection.dispose(); } }

Once Java actually gets closures it'll make this soooo much nicer.