In JDK 1.6, Doug Lea uses final
preceding the next
field.
static final class HashEntry<K,V> {
final K key;
final int hash;
volatile V value;
final HashEntry<K,V> next;
Whereas in JDK 1.7, the next
field is preceded by volatile
. I also notice that in JDK 1.7, the get
method adopts getObjectVolatile
method to read the value
field, which has the volatile load semantics.
I have no sense why Doug Lea previously uses final
. If there are problems with correctness, then how could he replace it with volatile
in JDK 1.7(also JDK 1.8)?
Edit:
Specifically, my question is that could we replace final
with volatile
in JDK 1.6's implementation?