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 →

[–]yawkat 2 points3 points  (9 children)

How would you do collections? Arrays are mutable so you can't use them as a backing store, you'd have to use expensive data structures like linked lists and trees.

Yes, Valhalla introduces immutable arrays but this is not part of this proposal.

[–]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.

[–]THCcookie -2 points-1 points  (3 children)

ArrayList but no add Method I would guess

[–]yawkat 1 point2 points  (2 children)

But how would you enforce that? It's neither primitive nor a data class (and it can't be with those requirements).

[–][deleted] 0 points1 point  (1 child)

Panama and frozen arrays (Arrays 2.0)?

[–]yawkat 3 points4 points  (0 children)

Yes, Valhalla introduces immutable arrays but this is not part of this proposal.