java 5, switch and autoboxing
807605Jul 4 2007 — edited Jul 5 2007hi all,
i already asked my collegues and no one was able to help me.
i have to understand it for the SCJP exam (java 1.5)
so it would be really helpful if some of you could help me.
the following problem:
final int iP = 1;
final short sP = 126;
final byte bP = 2;
Short sLw = 3;
Byte bLw = 4;
Character cLw = 5;
Integer iLw = 6;
//switch (cLw){ // works fine
//switch (bLw){ // works fine
//switch (sLw){ // works fine
switch (iLw){ // the non-int cases FAIL - WHY?
case sP: System.out.println("");
case 'n': System.out.println("");
case bP: System.out.println("");
case iP: System.out.println("");
case 127: System.out.println("");
}
all works fine until i use an Integer wrapper as switch statement.
why do all the other wrapper types work, just the Integer one not?
i googled, but i just find the typical simple switch examples.
thanks a lot for your help
marcel