This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile Time Constant

 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you exactly mean by stating that a field is a
compile time constant
Please explain ???
 
Lamont Williams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some info I found that should be helpful.

A compile-time constant is a value that can be (and is) computed at compile-time. A runtime constant is a value that is computed only while the program is running. If you run the same program more than once:

A compile-time constant will have the same value each time the application is run.
A runtime constant can have a different value each time the application is run.
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Very Much

Regards
Prashanth Lingala
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you encountered the term when you read that there is a big-time gotcha with respect to compile-time constants. Consider the following scenario...



Now, if you compile these two java files and run class B, it will print out, "Hello". If you then change the "MESSAGE" variable in A.java to "Hello, World", compile A.java, and then run class B again, it'll print "Hello" still! It will not lookup the value of the "MESSAGE" variable dynamically at runtime. So, be careful. It helps if you use an IDE which keeps track of that stuff and knows that B needs to be recompiled because one of its dependencies has changed.
[ March 08, 2005: Message edited by: James Carman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic