This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complie time Constant - final int a; a =1 ; IS NOT?!

 
Ajay Chandravadiya
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As per the book and the compiler following is true.



Q. Why 'b' variable is NOT a Compile Time Constant?
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rule for a 'case' is compile- time constants, and variable 'b' isnt considered so, its assigned a value later hence not become compile time constant.
You would have to declare and inialize the final variable in 1 line, like this:
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
variable a is given value at compilation time only so its compile time constant
but variable b is not getting any value till it runs.so run time value assigned.
so not comiple time constant
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic