This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Switch And Primitive Wrappers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch And Primitive Wrappers" Watch "Switch And Primitive Wrappers" New topic
Author

Switch And Primitive Wrappers

Sam Samson
Ranch Hand

Joined: Oct 08, 2011
Posts: 61

Hi

I'm wondering why I can't use an Integer as a case constant:



Autoboxing seems to work in the switch() statement, but not for the case?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sam Samson wrote:Hi

I'm wondering why I can't use an Integer as a case constant:



Autoboxing seems to work in the switch() statement, but not for the case?


Because auto-unbox turns case finalInteger into case finalInteger.intValue(), and calling intValue() makes it non a constant.
Sam Samson
Ranch Hand

Joined: Oct 08, 2011
Posts: 61

Perfect explanation, thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Switch And Primitive Wrappers