How to handle Java errors and cleanup without finalize
After several years of rumblings, Java is preparing to deprecate the finalize method in JDK 18. This is covered by JDK Enhancement Proposal 421, which will mark finalize as deprecated and allow for it to be turned off for testing. It will remain default enabled. It will be removed entirely in a future release. On this occasion, let’s take a look at what the end of finalize means and how we should handle errors and resource cleanup now. [ Also on InfoWorld: How to detect the Log4j vulnerability in your applications ] What is finalize? Before we understand why finalize is going away and what to use instead, let’s understand what finalize is or was.To read this article in full, please click here
After several years of rumblings, Java is preparing to deprecate the finalize
method in JDK 18. This is covered by JDK Enhancement Proposal 421, which will mark finalize as deprecated and allow for it to be turned off for testing. It will remain default enabled. It will be removed entirely in a future release. On this occasion, let’s take a look at what the end of finalize means and how we should handle errors and resource cleanup now.
What is finalize?
Before we understand why finalize is going away and what to use instead, let’s understand what finalize is or was.