Adios to JAVA Finalizers

JEP 421 announces the end of Java Finalizers. Adios to an ancient Java feature, born together with Java 1.0 and its Garbage Collector.

Gaetano Piazzolla
2 min readJan 22, 2022

--

Photo by Pawel Czerwinski on Unsplash

Finally” and “Finalize

We need those keywords only for specific cases, namely, releasing the operating system’s resources. In those cases, the Garbage Collector is insufficient; the program must release OS resources programmatically.

Let’s provide a classic example of a “finally” block used to close an InputStream:

And let’s provide also the less used “finalize”, a method present in every Object class. This method It’s called when an OBJECT has been selected for Garbage Collection (just before deletion):

What are the problems of

--

--

Gaetano Piazzolla
Gaetano Piazzolla

Written by Gaetano Piazzolla

Tech. Writer and Passionate Developer.

Responses (1)