Object.finalize()
is called by the Garbage Collector at some point after the object becomes unreferenced.
In general, overloading Object.finalize()
is a bad idea because:
- The overload may not be called by the Garbage Collector.
- Users are not expected to call
Object.finalize()
and will get confused.
But beyond that it’s a terrible idea to name a method "finalize" if it doesn’t actually override Object.finalize()
.
Noncompliant code example
public int finalize(int someParameter) { // Noncompliant
/* ... */
}
Compliant solution
public int someBetterName(int someParameter) { // Compliant
/* ... */
}