The final
keyword identifies constant values. That is, final
indicates fields whose value cannot change during an invocation of a program.
However, constants that can change over the lifetime of a program should not be declared public final. The JLS allows implementations to insert the value of public final fields inline in any compilation unit that reads the field. Consequently, if the declaring class is edited such that the new version gives a different value for the field, compilation units that read the public final field may still see the old value until they are themselves re-compiled.
...
Code Block | ||
---|---|---|
| ||
class Bar { public static void main(String[] args) { printfSystem.out.println("You are using version " + Foo.VERSION); } } |
...
Code Block | ||
---|---|---|
| ||
class Bar { public static void main(String[] args) { printfSystem.out.println("You are using version " + Foo.getVersion()); } } |
...