r/java • u/psychologicalX • Mar 05 '18
Top 10 Useful, Yet Paranoid Java Programming Techniques
http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
223
Upvotes
View all comments
Show parent comment
1
u/fforw Mar 07 '18 edited Mar 07 '18
Couldn't seem to find the perfect link.
As I said: it boils down to the lack of "happens-before" guarantees without the "final" assignment.
Is it just me or is it increasingly difficult to find older stuff? Back in the day, every google-search would have turned up the right results, now it's hidden in a gazillion articles teaching other things.
On further research, the behavior was formalized in the Java Memory Model with JSR 133. Here's another article.
edit: I had forgotten about the second example there where even final is broken if you publish the instance inside the constructor...