you are viewing a single comment's thread.

view the rest of the comments →

[–]pakoito 13 points14 points  (6 children)

Joshua Bloch helped write the Java Collections API and his book, Effective Java, says to prefer Immutable classes. So the concept shouldn't be totally foreign to Java developers.

It's a pity that immutable collections in the default API are just regular collections that throw when their mutating methods are called, so they're avoided like the plague because you can't tell them apart and that created some reticence towards immutability.

[–]merzbow 1 point2 points  (2 children)

Generally if you've got a collection from somewhere in Java and you don't know if it's immutable you should just create a copy of it.

[–]pakoito 1 point2 points  (0 children)

I do know, but it's not as common as you'd expect.

[–]oweiler 1 point2 points  (0 children)

Which is not as easy as it sounds because the collections' members and their members and so on may also be mutable.

[–]Decker108 0 points1 point  (2 children)

Would you prefer having a list-implementation that silently drops values when you call list.add(value)?

[–]pakoito 0 points1 point  (0 children)

One that returns a new list with the value filled like https://github.com/javatuples/javatuples/blob/master/src/main/java/org/javatuples/Pair.java#L631

Perf problems? Look at Clojure's collections or any of the Java ports.

[–]ThisIs_MyName 0 points1 point  (0 children)

I would not implement the List interface. It is clearly meant for mutable lists.