title: Why does Set.of() throw an IllegalArgumentException if the elements are duplicates?
body: <p>In Java 9 new static factory methods were introduced on the Set interface, called of(), which accept multiple elements, or even an array of elements.</p>
  
  <p>I wanted to turn a list into a set to remove any duplicate entries in the set, which can be done (prior to Java 9) using:</p>
  
  <pre><code>Set&lt;String&gt; set = new HashSet&lt;&gt;();
  set.addAll(list);
  </code></pre>
  
  <p>But I thought it would be cool to use this new Java 9 static factory method doing:</p>
  
  <pre><code>Set.of(list.toArray())
  </code></pre>
  
  <p>where the <code>list</code> is a List of Strings, previously defined.</p>
  
  <p>But alas, java threw an <code>IllegalArgumentException</code> when the elements were duplicates, also stated in the Javadoc of the method. Why is this?</p>
  
  <p><strong><em>Edit</em></strong>: this question is not a duplicate of another question about a conceptually equivalent topic, the Map.of() method, but distinctly different. Not all static factory of() methods behave the same. In other words, when I am asking something about the Set.of() method I would not click on a question dealing with the Map.of() method.</p>