Posts

Showing posts from July, 2015

Understanding Immutable Classes In Java

I recently reviewed an article that claimed immutable classes in Java are not always thread safe. Ultimately, this is not true since any immutable class cannot contain state and therefore no two threads could change it's state. To understand this more, I would like to do a quick dive into what an Immutable class is in Java.

Yes, Immutable Means Thread Safe. It's that simple.

Plain and simple, IMMUTABLE IS ALWAYS THREAD SAFE, and it is a very simple concept. If somethings state cannot change upon instantiation, no two threads can ever write to the object and break it's state. The other day I was curious what people thought about this topic. A top hit from DZone claimed not always, and I would like to rebuttal. Here is a link. https://dzone.com/articles/do-immutability-really-means And my response: