При объявлении локального внутреннего класса внутри метода, почему законно включать конечные статические строки или ints, но не законно включать другие объекты?
Например:
class Outer {
void aMethod() {
class Inner {
final static String name = "compiles";
final static int ctr = 10; // compiles
final static Integer intThree = Integer.valueOf(3); // does not compile!
final static obj objConst = new Object(); // does not compile!
}
Inner inner = new Inner();
}
}
Когда я скомпилирую это, я получаю следующее:
InnerExample.java:6: inner classes cannot have static declarations
final static Integer outer = Integer.valueOf(3);
^
InnerExample.java:7: inner classes cannot have static declarations
final static Object objConst = new Object();
^
Почему различие? Это потому, что String неизменен? Если да, то не будет ли Integer.valueOf()?