Skip to content

What is a compile time constant in Java? What is the risk of using it?

Posted in Education, and WhoCodeFirst

Compile time constant and Risk

public static final variables are also known as a compile-time constant, the public is optional there. They are replaced with actual values at compile time because compiler know their value up-front and also knows that it cannot be changed during run-time.

Risk associate with Compile time constant

One of the problems with this is that if you happened to use a public static final variable from some in-house or third party library and their value changed later than your client will still be using old value even after you deploy a new version of JARs. To avoid that, make sure you compile your program when you upgrade dependency JAR files.

If you enjoyed this article, Get email updates (It’s Free)
Translate »