• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why can't the wrapper classes be switch statement expressions?

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, if I have the following:


Why can't i1 be a case expression?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rachel Glenn wrote:For example, if I have the following:


Why can't i1 be a case expression?



Case statements requires compile time constants. Currently, with Java, Integer objects are not compile time constants.

Henry
 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Rachel Glenn wrote:For example, if I have the following:


Why can't i1 be a case expression?



Case statements requires compile time constants. Currently, with Java, Integer objects are not compile time constants.

Henry



Is there is areason for that, or is that just the way it is? I find it confusing especially since wrapper objects are immutable.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rachel Glenn wrote:
Is there is areason for that, or is that just the way it is? I find it confusing especially since wrapper objects are immutable.



Short answer ...

http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28


As for the reason why, and/or whether this will change. you will need to contact the Java designers directly.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Also... forgot to mention... although string literals has been compile time constants for a very long time, their usage in a case statement is relatively new. So, in the future, perhaps Java will support Integer objects in case statements, which of course, will require that they be supported as compile time constants first.

Henry

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic