February 2014
Beginner
1248 pages
62h 25m
English
Every class in Java has the methods of class Object (package java.lang), one of which is method finalize. (You’ll learn more about class Object in Chapter 9.) You should never use method finalize, because it can cause many problems and there’s uncertainty as to whether it will ever get called before a program terminates.
The original intent of finalize was to allow the garbage collector to perform termination housekeeping on an object just before reclaiming the object’s memory. Now, it’s considered better practice for any class that uses system resources—such as files on disk—to provide a method that programmers can call to release resources when they’re no longer needed in a program. AutoClosable ...
Read now
Unlock full access