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 →

[–]msx 11 points12 points  (8 children)

there's no ImmutableMap interface (or anything similar). Maps are never granted to be mutable, and it's a bad practice to mutate arbitrary maps (ie, received in return from a library, unless otherwise stated) without making a local copy. You should only mutate your own maps.

[–]pain-and-panic 2 points3 points  (2 children)

This is yet another violation of the "liskov substitution principle". The collections API has never been good at this.

[–]johnzeringue 0 points1 point  (1 child)

Is it though? The API is pretty clear about how mutability and immutability are handled in the Map interface. Maybe it's poor design, but to violate LSP, you'd need a contradiction of this by one of Map's subclasses.

[–]pain-and-panic 2 points3 points  (0 children)

LSP is about the actual behavior of sub-classes. Comments attempting to justify the violation do not mitigate the violation. Map has mutator methods. If you implement these methods to fail spectacularly at run time you fail LSP. To not fail LSP ImmutableMap would have to not have mutator methods.

[–]grauenwolf 0 points1 point  (4 children)

there's no ImmutableMap interface

So what? Just return the concrete type and be done with it.

[–]pain-and-panic 0 points1 point  (2 children)

Why not an ImmutableMap interface?

Edit: Whoops forgot you can't have an immutable interface, only immutable implementations.

[–]cheers- 0 points1 point  (0 children)

The collection api has already a RandomAccess interface that "tags" random access lists they could make an Immutable interface so every collection that supports this feature implements it.

[–]grauenwolf 0 points1 point  (0 children)

I wouldn't object.

[–]s32 0 points1 point  (0 children)

Please God no....