...
In the presence of multiple threads, non-final public static
fields can be modified in inconsistent ways. (See guideline rule "TSM01-J. Do not let the (this) reference escape during object construction" for an example.)
...
Fields declared static final
are also safe for multithreaded use. (See guideline rule "TSM03-J. Do not publish partially initialized objects.") However, remember that simply changing the modifier to final
might not prevent attackers from indirectly retrieving an incorrect value from the static
final
variable before its initialization. (See guideline rule "DCL12-J. Prevent class initialization cycles" for more information.) Furthermore, individual members of the referenced object can also be changed if the object itself is mutable. (See guideline rule "OBJ02-J. Never conflate immutability of a reference with that of the referenced object.")
It is also permissible to use a wrapper method to retrieve the value of m_functions
. This has encapsulation advantages because it permits m_functions
to be declared private
. See guideline rule "OBJ01-J. Declare data members as private and provide accessible wrapper methods" for more information.
...