> static void writer() { > f = new FinalFieldExample(); > } > static void reader() { > if (f != null) { > int i = f.x; // guaranteed to see 3 > int j = f.y; // could see 0 > } > } > } >
In this snippet of code there's not even a guarantee that reader() will see the change to field f... I used to create puzzlers for students around spin loops that got optimized away by hotspot to never again reference the (condition) field because the code never mutated it inside the loop. So something like this: while (f == null) {} should get jitted into this: while (true) {} D.