Rod Johnson on The Spring Framework Microsoft view of JavaOne
Jul 07

Would you like using() in Java?

Tech Add comments

I have been talking to a bunch of people here and there about C#/.NET and Java.

People either seem to love of hate the using() statement in C#

One end of the spectrum:

Uh. Is try {} finally {} that hard?

to the other:

I don’t know how I lived without the convenience. It is just so nice to be able to use the using paradigm. You get used to having classed that implement IDisposable and everything gets taken care of for you.

I personally kinda like it. However I would rather just have closures in the language, as they can take care of this stuff for you… and much much much much more.

What do you think?

One Response to “Would you like using() in Java?”

  1. James Strachan Says:

    When we first started Groovy we thought using might be interesting – it turns out using is really limited – its of little use.

    As Jon says, what you really need is closures. Then you can do real stuff (like JDBC queries or file piping) and easily handle the closing of multiple resources with complex exception semantics – yet to the developer it looks really simple & easy – even if the exception handling & resource closing logic can be kinda complex.

    http://groovy.codehaus.org/Groovy+SQL

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'