Compile-time Constant (CloudMonk.io)

Compile-time constant




"Normally, it is the JVM that sets the values of Java variables when a Java program is executed. The Java compiler does not execute any Java code and it has no knowledge of the values that a variable might take during the execution of the program. Even so, in certain cases, it is possible for the compiler to figure out the value of a variable. If a compiler can determine the value that a variable will take during the execution of the program, then that variable is actually a compile-time constant. For example, if you define an int variable as final int x = 10; then x is a compile time constant because the compiler knows that x will always have a value of 10 at run time. Similarly, Java literals such as the numbers 1, 2, and 3, or the characters written in code within single quotes such as 'a', or Java boolean values true and false, are all compile time constants because the compiler knows that these values will never change."

Fair Use Source: Deshmukh 2018