Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

Java Equivalent to the C# 'using' Statement

The C# 'using' statement (not the C# 'using' directive) is syntactic sugar for a try/finally block which disposes an object. Java 8 introduces the 'try with resources' statement:

C#:

using (Foo f = new Foo())
{
}

Java 7 or higher:

try (Foo f = new Foo())
{
}

pre-Java 7:

Foo f = new Foo();
try
{
}
finally
{
   f.dispose();
}

If you need to convert from C# to Java and you are depending on the results being reliable and accurate, then you will want to have C# to Java Converter, the best C# to Java converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.