Mr said:
Invaluable if you actually need it, but it is rare to need it.
so what? it's a good thing?
No, a method with the kind of dependencies / assumptions you describe is
a bad thing. The absence of support for it in Collection is therefore a
non-issue. There might conceivably be a more appropriate context for
your criticism of Collection's lack of the feature you desire, but I'm
not seeing it.
yes but not handy, several checks needed instead of one in the constructor for example
No, no checks are required. If the method needs a collection for
internal purposes then it doesn't matter whether the one passed in has
suitable characteristics -- the method still needs to create its own.
"Of course" that's a problem, or "of course" the object should indicate
that it supports duplicates? The latter position is not self-evident to
me because given a List such as I describe, I cannot cause it to contain
duplicate elements. Is it then right to say that it supports them?
Perhaps the _class_ allows duplicate elements, so maybe the object
_should_ claim to support duplicates, but that isn't relevant to what I
can do with it.
because of this, i don't use Collection, but List and Set, and i don't mix them, which sucks.
Collection is a rather abstract interface, and it is intended to be so.
There are plenty of valid contexts for its use. There are also plenty
of contexts where use of List or Set instead is appropriate. I don't
see anything wrong with having to be more specific in some places, but
being free to be more abstract in others. It matches well with
component requirements and guarantees.
If you are not using direct Collection implementations then I see no
basis at all for your complaint. If you need an argument to be a List
then declare it a List. There is no advantage whatever to declaring it
a Collection and then checking after the fact that it is actually a List.
If you bring direct Collection implementations into the picture then
there is at least some cause for concern, but for the most part the
preceding paragraph still applies. There has been no outcry from the
community on this particular issue because it is rarely a problem in
practice.
Now on the other hand, don't get me started on mutable vs. immutable
collections and UnsupportedOperationException....