• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

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 7 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();
}


Use C# to Java Converter to convert from C# to Java.     

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.