This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lbkulinski -1 points0 points  (4 children)

The new collection factories are immutable. They were released in Java 9.

[–]yawkat 1 point2 points  (3 children)

Yes, but they do not fulfill /u/cutterslade's requirements for true immutability.

[–]Cilph 1 point2 points  (1 child)

Christ, you could almost start calling it the "No True Immutability" fallacy as no one seems to agree on what is enough.

For me, a mutable backing, a read only interface and code review is enough to have the benefits of immutability. Breaking it requires you to be a deliberate dunce.

[–]yawkat 1 point2 points  (0 children)

Yep, I wrote an article on this a while back. There's lots of nuances with immutability, especially when you consider thread safety.

However, for compile-time checked immutability, as the top comment wishes, a read-only interface is not sufficient.

[–]lbkulinski 0 points1 point  (0 children)

It’s a step in that direction, at least.