This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes problem in switch case Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "problem in switch case" Watch "problem in switch case" New topic
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
    
  19

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in switch case
 
Similar Threads
A switch-case statement question
overload method in boxing/unboxing
what is compile time constant in switch case?
Wrapper Classes for Switch
compile time constant