File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes problem in switch case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
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: 1776
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: 1776
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: 19064
    
  40

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: 19784
    
  20

Currently, Strings are the only non-primitive compile-time constants.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in switch case