1 /*
2 NoFinalizer
3
4
5 */
6
7 package com.puppycrawl.tools.checkstyle.checks.coding.nofinalizer;
8
9 public class InputNoFinalizerHasFinalizer
10 {
11 public void finalize() // violation 'Avoid using finalizer method.'
12 {
13 // It's not enough to check if the METHOD_DEF branch contains a PARAMETER_DEF, as that would
14 // treat this method as having a parameter.
15 Runnable runnable = new Runnable() {
16
17 public void run() {
18 reallyFinalize("hi");
19 }
20
21 // generates a PARAMETER_DEF AST inside the METHOD_DEF of finalize()
22 private void reallyFinalize(String s)
23 {
24 }
25 };
26 runnable.run();
27 }
28
29 // should not be reported by NoFinalizer check
30 public void finalize(String x)
31 {
32 }
33 }