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).