3 ms·
Isn't this what the AutoCloseable interface (combined with try-with-resources statements) addresses for everything except memory? It wasn't added until Java 1.7
by markdoubleyou 9y ago
Isn't this what the AutoCloseable interface (combined with try-with-resources statements) addresses for everything except memory? It wasn't added until Java 1.7, though, so maybe the article predates that feature.
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html https://docs.oracle.com/javase/tutorial/essential/exceptions...
...basically it's the same as .NET dispose pattern for achieving deterministic cleanup. Most IDEs and code analysis tools will throw a fit if you don't use an AutoCloseable/IDisposable class properly in a try-with-resources/using statement.
- maxxxxx 9y agoThe dispose pattern puts the work on the user of the resource. In addition I have seen cases of classes that didn't need to be disposable but later changes were made that required them to be disposable. Now you have code using these classes that don't dispose them. I much prefer destructors like in C++ (or VB or even PHP) that run when the reference count goes to 0.