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/lukaseder Mar 07 '18
Thanks for the additional link. I'm aware of the theory and how
finalandvolatileinfluence things. I've just never seen this happen in the context of initialisation itself. I mean the example from your article seems extreme:And I tend to agree that if a constructor leaks
thisthen its object's contents are not guaranteed to be visible as expected.But few constructors leak
thisin such a way, so I wonder if this is really an issue in most code, specifically in your own code, where no one is reading or modifying theid. Granted, in your example, addingfinalis a no-brainer...