Since Checkstyle 5.0
Checks that there is no method finalize
with zero parameters.
Rationale: Finalizers are unpredictable, often dangerous, and generally unnecessary. Their use can cause erratic behavior, poor performance, and portability problems. For more information for the finalize method and its issues, see Effective Java: Programming Language Guide Third Edition by Joshua Bloch, §8.
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="NoFinalizer"/> </module> </module>
Example:
public class Test { protected void finalize() throws Throwable { // violation try { System.out.println("overriding finalize()"); } catch (Throwable t) { throw t; } finally { super.finalize(); } } }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.coding