Reports instance initializers which can be made static without producing any errors.

인스턴스 이니셜라이저가 클래스의 static이 아닌 멤버를 참조하지 않는 경우 static일 수 있습니다. Static initializers are executed once when the class is resolved, while instance initializers are executed on each instantiation of the class.

이 검사는 인스턴스가 비어 있는 이니셜라이저와 익명 클래스의 이니셜라이저를 보고하지 않습니다.

예:


  class A {
     public static String CONSTANT;
     {
        CONSTANT = "Hello";
     }
  }

빠른 수정을 적용한 후:


  class A {
     public static String CONSTANT;
     static {
        CONSTANT = "Hello"; // 클래스당 1회만 초기화됩니다
     }
  }