4 ms·
Java 7 has AutoCloseables for resource cleanup: try (FileInputStream f = new FileInputStream(path)) { // do stuff }
by klon 14y ago
Java 7 has AutoCloseables for resource cleanup:
try (FileInputStream f = new FileInputStream(path)) {
// do stuff
}
- dvhh 14y agoAbout fucking time
- draven 14y agoThe python mechanism is more general, you can use the /with/ construct with locks for example.
- andrewaylett 14y agoYou can do the same with Java. Both are in a sense trying to re-gain the most useful parts of RAII semantics from C++: making it much more difficult to forget to clean up resources after you've finished with them.
- draven 14y agoOr the unwind-protect faciliy from Common Lisp, that is "cleanup stuff before it goes out of scope"