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

Java Equivalent to the C# 'using' Statement

The C# 'using' statement (not the C# 'using' directive) is a shortcut for a try/finally block which disposes an object of type System.IDisposable. Java 7 introduces the 'try with resources' statement, which operates on objects of type java.io.Closeable:

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


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

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2018 Tangible Software Solutions, Inc.