Does Java have a using statement?
问题 Does Java have a using statement that can be used when opening a session in hibernate? In C# it is something like: using (var session = new Session()) { } So the object goes out of scope and closes automatically. 回答1: Java 7 introduced Automatic Resource Block Management which brings this feature to the Java platform. Prior versions of Java didn't have anything resembling using . As an example, you can use any variable implementing java.lang.AutoCloseable in the following way: try