Constant expression contains invalid operations [duplicate]

As described here Class member variables are called “properties”. You may also see them referred to using other terms such as “attributes” or “fields”, but for the purposes of this reference we will use “properties”. They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This … Read more

Compile-time constants and variables

Compile time constant must be: declared final primitive or String initialized within declaration initialized with constant expression So private final int x = getX(); is not constant. To the second question private int y = 10; is not constant (non-final in this case), so optimizer cannot be sure that the value would not change in … Read more