Skip to main content

'using' block

1 reply [Last post]
dirk5000
Offline
Joined: 2010-09-04

there's one thing I really miss in Java: a 'using' block like C# has:
using (TemporaryObject obj = new TemporaryObject()) {
...
}

now takes:
TemporaryObject obj = null;
try {
obj = new TemporaryObject();
...
} finally {
if (obj != null)
obj.dispose();
}

could you make Java 7 support this feature?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alanb
Offline
Joined: 2005-08-08

Look at the try-with-resources construct in jdk7.