Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
bgColor#ffcccc
class Bar {
  public static void main(String[] args) {
    printfSystem.out.println("You are using version " + Foo.VERSION);
  }
}

...

Code Block
bgColor#ccccff
class Bar {
  public static void main(String[] args) {
    printfSystem.out.println("You are using version " + Foo.getVersion());
  }
}

...