• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in switch case

 
Nittin singla
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry nitin - i deciphered your question wrongly. Case does not allow wrapper ( or any other object). only primitives
 
Henry Wong
author
Marshal
Pie
Posts: 21427
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently, Strings are the only non-primitive compile-time constants.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic