I'm wondering if putting a return statement inside a try-with-resources block prevents the resource to be automatically closed.
try(Connection conn = ...) {
return conn.createStatement().execute("...");
}
If I write something like this will the Connection be closed? In the Oracle documentation it is stated that:
The try-with-resources statement ensures that each resource is closed at the end of the statement.
What happens if the end of the statement is never reached because of a return statement?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…