コーディング中に、Java コンパイラーの奇妙な動作に遭遇しました。
クラス (以下のソース) をコンパイルすると、コンパイラはinner classes cannot have static declarationsNULL クラス変数でエラー (" ") を出力します。これは予想通り!
ただし、ZERO クラス変数ではエラーは発生しません。これはわかりません!
内部クラスでは、オブジェクトではなく単純な型の静的宣言を許可しているように見えるこの違いはなぜですか。
(javac -バージョン: 1.6.0_24)
public class Outer {
    public static final Runnable HELLO = new Runnable() {
        // No compiler error
        public static final int ZERO = 0;
        // Causes compiler error: "inner classes cannot have static declarations"
        public static final Object NULL = null;
        @Override
        public void run() {
            System.out.println("Hello " + ZERO + NULL);
        }
    };
}