I made a crazy discovery today in Java and I would like to know why.
The following switch statement works
public static final String OTHER_OTHER = ”.otherOther”;
…
switch (SWITCHER) {
case Dogs.OTHER_OTHER:
doMyWork(intent);
break;
default:
...;
}
Fails to compile
public static final String OTHER_OTHER = Dogs.class.getPackage().toString()+”.otherOther”;
…
switch (SWITCHER) {
case Dogs.OTHER_OTHER:
doMyWork(intent);
break;
default:
...;
}
The only difference between the two snippets is in how I constructed the constant OTHER_OTHER
The second switch statement is complaining that OTHER_OTHER is not a constant. I am creating a String of all thing, using final
.