Slide 5
Slide 5 text
Use static final for constants
static int intVal = 42;
static String strVal = "Hello, world!";
The compiler generates a class initializer method, called , that is executed when the class is
first used. The method stores the value 42 into intVal, and extracts a reference from the classfile string
constant table for strVal. When these values are referenced later on, they are accessed with field
lookups.
We can improve matters with the "final" keyword:
static final int intVal = 42;
static final String strVal = "Hello, world!";