title: Java unmodifiable set casted to an enumset
body: <p>I would like to make test unmodifiable, so I'm using <code>Collections.unmodifiableSet</code> and casting, as per <a href="https://stackoverflow.com/a/3603830/2719355">this answer.</a></p>
  
  <pre><code>EnumSet&lt;T&gt; test = (EnumSet) Collections.unmodifiableSet(EnumSet.of(T.Enum.A));
  </code></pre>
  
  <p>But I keep getting the following. What's wrong with the above? </p>
  
  <pre><code>java.lang.ClassCastException: java.util.Collections$UnmodifiableSet cannot be cast to java.util.EnumSet
  </code></pre>