File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ajay Chandravadiya
Greenhorn
Posts: 27
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic