17.5. final Field Semantics
Fields declared final are initialized once, but never changed under normal circumstances. The detailed semantics of final
fields are somewhat different from those of normal fields. In particular, compilers have a great deal of freedom to move reads of final
fields across synchronization barriers and calls to arbitrary or unknown methods. Correspondingly, compilers are allowed to keep the value of a final
field cached in a register and not reload it from memory in situations where a non-final
field would have to be reloaded.
final
fields also allow programmers to implement thread-safe immutable objects without synchronization. A thread-safe immutable object is seen as immutable by all threads, even if a data race is ...
Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.