This is a question about the java try-with-resources statement.
If I declare an object outside the parentheses of try()
as shown below, will it result in a compilation error?
MyResource obj1;
try(obj1 = new MyResource("obj1")}
// processing
} catch(SQLExceptione){
// exception handling
}
Yes, compile error.
The try-with-resources statement is a try statement that declares one or more resources.
However, in a newer version of Java, you can also write in the same way as you can find on this page.
© 2024 OneMinuteCode. All rights reserved.