Hacker News new | ask | show | jobs
by FurrBall 4652 days ago
Reality is there are many Java code bases which handle resources like this. For java 6 and below this not bad code; it is how you are forced to deal with resources.

Even with the new block syntax, you have painful nesting if the operation requires several disparate resources.

Blocks are an improvement, but not the same as RAII. A block is literally converted to a try-finally by the compiler. It is the same thing with a cleaner syntax. There is no safety added to the old Java way. A programmer can forget to put his stuff in a block and leak the resource the same as he forgets to use a try-finally. The onus is on the consumer, not the library writer.

With RAII the onus is removed from the consumer. The consumer writes safe code automatically, no onus to remember any special clean up idioms.