| Author |
problem in switch case
|
Nittin singla
Greenhorn
Joined: Jul 02, 2011
Posts: 24
|
|
In the following code, final int is considered as a constant but final Integer isnt considered so...So it results in a compile time error...Acc to me, final Integer is also a constant..Can someone please tell em the reason why compile time error comes?
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
Nittin singla wrote:but final Integer isnt considered so...So it results in a compile time error...
Can you tell how you think it's not considered and wat is the error you receive
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
|
Sorry nitin - i deciphered your question wrongly. Case does not allow wrapper ( or any other object). only primitives
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
Nittin singla wrote:In the following code, final int is considered as a constant but final Integer isnt considered so...So it results in a compile time error...Acc to me, final Integer is also a constant..Can someone please tell em the reason why compile time error comes?
In addition to John's answer, a constant, specifically a compile time constant, is defined by the Java Language Specification. And in the current version of the specification, Integer instances are not to be considered as compile time constants.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Currently, Strings are the only non-primitive compile-time constants.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: problem in switch case
|
|
|