public class Test {
public enum Directions {
NORTH, WEST, SOUTH, EAST
}
static final Directions D1 = Directions.NORTH;
static class Inner {
static final Directions D2 = Directions.NORTH;
}
class Inner2 {
static final Directions D3 = Directions.NORTH;
}
}
I am getting the IDE-Error which is in the title, referring to the variable D3. Can someone explain that to me? Why can I not declare a static variable in an inner class that is not static and why is the enum value not a constant?
Inner classes may not declare static members, unless they are constant variables (§4.12.4), or a compile-time error occurs.
Enum
entry not considered a constant variable?A variable of primitive type or type String, that is final and initialized with a compile-time constant expression (§15.28), is called a constant variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With