This is my switch
statement:
switch (aXxx.actionType()) {
case Xxx.TYPE_A:
break;
case Xxx.TYPE_B:
break;
case Xxx.TYPE_C:
break;
case Xxx.TYPE_D:
break;
}
And this is my constant declarations (defined on another class, Xxx
):
public final static Integer TYPE_A = 610921;
public final static Integer TYPE_B = 610922;
public final static Integer TYPE_C = 610923;
public final static Integer TYPE_D = 610924;
Seeing this, my compiler (I'm using IntelliJ-based Android Studio 2.1) refused to compile my code saying:
Constant expression required.
I can't understand the reason why; those are constants and I did initialize their values (unlike the case on this SO question).
I tried changing their type to primitive int
, the error disappeared and my code compiled just fine.
But what's the real reason behind this?
p.s., For those who are wondering why I don't use enum
s for this: I work on Android and I'm intending to use those constants as @IntDef
values.