For various business reasons, I want to store some static identifiers in one of my classes. They were originally int , but I wanted to change them to Integer so that I could do equal to them (i.e. MY_ID.equals(..) , which avoids NPE)
When I change them to Integer, I get errors in my switch statement. docs say that Integer should be in order between the switches.
To quote
[Switch] also works with enumerated types (discussed in Enum types), the String class, and several special classes that wrap certain primitive types: character, byte, short, and integer (discussed in Numbers and Strings).
In my code below, if I am int then it compiles. When it is Integer , it does not say that a constant expression is required . I tried to do .intValue() , but this does not work either.
Am I really stupid? Or read docs completely incorrectly?
private static final Integer i = 1; @Test public void test() { switch(mObj.getId()){ case i:
Thanks for any pointers here. For now, I save them as int and do new Integer(myint).equals(...)
source share