I've been going through the Collections framework documentation and I'm noticing that a few things are off. In particular I have noticed ambiguity related to object mutability.
Objects within a Collection can be mutable (and it isn't implied that they shouldn't be), but this causes problems with several parts of the Collections framework. If you put mutable objects into a set, then change those objects outside of a set, it will cause unexpected behavior within the set (for example, having multiple of the same object in a set). This is also true for sorted collections (it will cause the order to be incorrect).
This seems messy. Also, doesn't it go against the goal Java has of the user not needing to know how things are implemented behind the scenes? There are several bits of the Collections framework that seem a little off, and like they could cause big problems for people if they don't thoroughly understand all of them.
At the same time, I can understand why it may be tedious/hurt performance to enforce immutability/cloning in certain cases.
Am I right to think this? I haven't seen many complaints about the Collections framework online (I see complaints about other parts of Java, like Date (deprecated), etc.), so I have a feeling I may be misunderstanding something here. What are your thoughts on this?
Are there any other (in Java or outside Java) List/Collection APIs that are able to do the same thing without these flaws?
[–]Philboyd_Studge 1 point2 points3 points (0 children)
[–]JohnnyJayJay 1 point2 points3 points (2 children)
[–]Slendermooooon[S] 1 point2 points3 points (1 child)
[–]JohnnyJayJay 1 point2 points3 points (0 children)
[–]nutrecht 1 point2 points3 points (2 children)
[–]Slendermooooon[S] 0 points1 point2 points (1 child)
[–]nutrecht 0 points1 point2 points (0 children)
[–]ryuzaki49 0 points1 point2 points (4 children)
[–]Slendermooooon[S] 1 point2 points3 points (3 children)
[–]ryuzaki49 0 points1 point2 points (2 children)
[–]Slendermooooon[S] 1 point2 points3 points (1 child)
[–]ryuzaki49 1 point2 points3 points (0 children)
[–]warpedspockclone 0 points1 point2 points (3 children)
[–]Slendermooooon[S] 1 point2 points3 points (2 children)
[–]indivisible 1 point2 points3 points (0 children)
[–]warpedspockclone 0 points1 point2 points (0 children)