Brian Goetz brian.goetz at oracle.com
Fri Dec 18 17:48:35 UTC 2015

> Limiting value type V to only override equals(V x) seems to have
> the same simplifying impact on Collection.contains and others. Yes?

In our attempt on Collections, we found that contains(V), while 
prettier, might not be enough.  In particular, it wasn't enough for 
providing the skeletal implementation of removeAll(Collection<? extends 
V>) in AbstractCollection, which looks like:

Iterator<E> it = iterator();
while (it.hasNext()) {
     if (c.contains(it.next())) {
         modified =true;

Here, c is a Collection<? extends E>, so its contains method would be 
contains(capture(? extends E)), and it.next() returns a E, so the 
compiler doesn't like it.  If I found this idiom in the first few 
minutes of trying to port collections, I'm guessing it will occur 
elsewhere too.

So perhaps what this says is we are going to get pushed in the other 
direction -- that we'll want to superate equals().

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/valhalla-spec-experts/attachments/20151218/f66d5eaf/attachment.html>

More information about the valhalla-spec-experts mailing list