aspose file tools*
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 Spring in Action this week in the Spring 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