[11] RFR: 8193128: Reduce number of implementation classes returned by List/Set/Map.of() (original) (raw)

Peter Levart peter.levart at gmail.com
Mon Jan 8 19:49:22 UTC 2018


On 01/08/18 20:46, Peter Levart wrote:

Or better yet, compute the size of the other set as you iterate the elements. Like this: public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Set)) return false; int osize = 0; for (Object e : (Iterable<?>) o) { if (!contains(e)) { return false; } osize++; } return size() == osize; } ...since calling .size() on the passed-in Set might not be free.

Ops, forgot to check for null 'e':

        @Override         public boolean equals(Object o) {             if (o == this)                 return true;

            if (!(o instanceof Set))                 return false;

            int osize = 0;             for (Object e : (Iterable<?>) o) {                 if (e == null || !contains(e)) {                     return false;                 }                 osize++;             }             return size() == osize;         }

Regards, Peter



More information about the core-libs-dev mailing list