Dear users,

While looking at the implementation of Set.of(...) I noticed that
duplicate elements are not allowed, e.g. Set.of(1, 1) will throw an
IllegalArgumentException. Why has it been decided to do this?

My expectation was that duplicates would simply be removed.

If I do for instance new HashSet<>(<collection containing duplicates>)
it works and duplicates are removed. To me, it looks a bit inconsistent
to have duplicates removed for a collection passed in the constructor,
but not for a collection (even though it is a vararg array) passed to a
static factory method.

Kind regards,

Dave Franken

Reply via email to