The class 'Effectively Immutable', as Java Concurrency In Practice defines the term.
This means that, as long as references to instances are 'safely published', they are immutable. Safely publishing the reference involves using synchronisation such that the Java Memory Model (JMM) can guarantee that callers will see the value of the field fully written. For example, if the field is not final, and an instance is constructed and passed to another thread, the other thread may see the field in an undefined state (such as null
if it's an object reference, or only half of a 64-bit long
field).
If the instance is only used in a single thread, then the distinction doesn't matter. This is because the JMM uses 'within-thread as-if-serial' semantics. Thus the assignment of a field within a constructor will always happen before the field can be read.
If the field was final
, the JMM would guarantee that callers would see the correct value, no matter how the reference was published. So final
has a benefit if you want to pass the instance to other threads without using forms of synchronisation.