Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java 5, switch and autoboxing

807605Jul 4 2007 — edited Jul 5 2007
hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2007
Added on Jul 4 2007
22 comments
370 views