File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Switch And Primitive Wrappers

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
IntelliJ IDE Java jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect explanation, thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic