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 回だけ初期化されるようになりました
     }
  }