Hi all, the current implementation of Set.copyOf(Collection<? extends E> coll) creates an intermediate HashSet object to remove duplicates even when coll is already a Set. The attached patch adds an additional check whether coll is already a Set and if yes, then calls #toArray() directly on coll and passes the result to Set.of().
And when I have already your attention: the constructors of SetN and MapN may throw a NegativeArraySizeException when the length of the input is greater than Integer.MAX_VALUE / 2 + 1. Maybe this should be documented or we should throw IllegalArgumentException and explain what's went wrong. Best regards, Andrej Golovnin