This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

case label int-compatible variable

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
howdy friends!

This is a question from the round-up game: http://www.javaranch.com/game/game2.jsp

In a switch statement, the argument to the case label (case: argument) can be any variable which can fit within an int.

Answer: false
The case argument must be either an int literal, or an int-compatible variable which is a constant (i.e. static final)

I agree with the answer, but I think there is one problem in the question and other in the explanation.

It should be (case argument:) and the other problem is when it says ... constant (i.e. static final)

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The case arguments must be Compile-time constants
when you mark some variable final and assign it a value , then it is a compile time constant.

It should not be static, it should be Compile time constant and that means it must be final and initialized!!!

static finals are called constants because of some historical reasons..... ( In accordance to Henry Wong )

otherwise final variables are constants.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look on here, here, here, and here. Go through them, you'll get a clear idea!

Before ask, have a Google search!
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea dude, they must be final.

Imagine if their value changes, the java would lose the reference.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic