Best Practices: Don't make the finalize() method public.

Overview

finalize() can be so easily mis-used and cause serious performance problems for your system that many recommend not to use it. However something your shouldn't do is make it public.

Don't make finalize() public

From ServiceRegistry
public void finalize() throw Throwable {
   deregisterAll();
   super.finalise();
}
If you have clean up functionality you want the caller to make e.g. close(); use a different method. In this case, the only method used is public, so there is no good reason to make the finalize() method public.

Comments

Popular posts from this blog

Java is Very Fast, If You Don’t Create Many Objects

Hands-On Career: The Evolution of a Java Champion

Demystifying Java Object Sizes: Compact Headers, Compressed Oops, and Beyond