View Javadoc
1   /*
2   FinalClass
3   
4   
5   */
6   
7   package com.puppycrawl.tools.checkstyle.checks.design.finalclass;
8   
9   import java.util.ArrayList;
10  
11  public final class InputFinalClass2
12  {
13      private InputFinalClass2() {}
14  }
15  
16  enum testenum1
17  {
18      A, B;
19      testenum1() {}
20  }
21  
22  enum testenum2
23  {
24      A, B;
25      // violation below 'Class someinnerClass should be declared as final'
26      public static class someinnerClass
27      {
28          private someinnerClass() {}
29      }
30  }
31  
32  interface TestInterface {
33      class SomeClass { // violation 'Class SomeClass should be declared as final'
34          private SomeClass() {}
35      }
36  }
37  
38  @interface SomeAnnotation {
39      class SomeClass { // violation 'Class SomeClass should be declared as final'
40          private SomeClass() {}
41      }
42  }
43  
44  class TestAnonymousInnerClasses {
45      public static final TestAnonymousInnerClasses ONE = new TestAnonymousInnerClasses() {
46          @Override
47          public int value() {
48              return 1;
49          }
50      };
51  
52      private TestAnonymousInnerClasses() {
53      }
54  
55      public int value() {
56          return 0;
57      }
58  }
59  
60  class TestNewKeyword { // violation 'Class TestNewKeyword should be declared as final'
61  
62      private TestNewKeyword(String s) {
63          String a = "hello" + s;
64      }
65  
66      public int count() {
67          return 1;
68      }
69      public static final TestNewKeyword ONE = new TestNewKeyword("world");
70      public static final test6 TWO = new test6() {
71      };
72  
73      public static void main(String[] args) {
74          ArrayList<String> foo = new ArrayList<>();
75          foo.add("world");
76          foo.forEach(TestNewKeyword::new);
77      }
78  }
79  
80  interface TestNewKeywordInsideInterface {
81      ArrayList<String> foo = new ArrayList<>();
82  }
83  
84  // abstract classes cannot be final
85  abstract class TestPrivateCtorInAbstractClasses {
86      private TestPrivateCtorInAbstractClasses() {
87      }
88  }
89  
90  class TestAnonymousInnerClassInsideNestedClass {
91      private TestAnonymousInnerClassInsideNestedClass() { }
92  
93      static class NestedClass { // violation 'Class NestedClass should be declared as final'
94  
95          public final static TestAnonymousInnerClassInsideNestedClass ONE
96                  = new TestAnonymousInnerClassInsideNestedClass() {
97          };
98  
99          private NestedClass() {}
100     }
101     static class NestedClass2 {
102 
103         private NestedClass2() {}
104 
105         public static final test6  ONE = new test6() {
106 
107             public final NestedClass2 ONE = new NestedClass2() {
108 
109             };
110         };
111     }
112 }
113