Hacker News new | past | comments | ask | show | jobs | submit login

I wonder why in the middle of 2022 people still put pre-2011 and pre-JDK7 snippets. And even try-with-resources example is not all what JDK7 provides, there are better, high-level utilities added which haven't got a proper attention.

Namely, in JDK7 and newer, you can just write: Files.readAllBytes(Path.get("story.txt"))




The point of the article was to compare how resource cleanup works in general in different languages. What you show here is a very special case that does not extend to other resources or even other file operations. Still, try-with-resources and AutoClosable is the best what Java has to offer, and it is clearly inferior to Rust/C++ approach (and to some degree also to Go and Zig, but less so).




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: