java source code:
static {
try {
valueOffset = unsafe.objectFieldOffset
(AtomicBoolean.class.getDeclaredField("value"));
} catch (Exception ex) { throw new Error(ex); }
}
default constructor do nothing:
public AtomicBoolean() {
}
The variable 'valueOffset' means the offset location in memory? I don't understand why it initialized to 'false' by default constructor.How can i understand this?
As no value is set in the default constructor, the initial value is the initialized value of the
valuefield - that's an int, with no explicit value, so it has the default value of zero.Source code:
Setting it to
falseis consistent with an uninitializedbooleanfield.