Usage of sun.misc.SharedSecrets
<p>I found this little gem in our codebase at work recently. I have to confess that I have absolutely no idea why this enum was written in this way (names changed to protect the innocent):</p>

<pre><code>package foo.bar;

import sun.misc.SharedSecrets;
import foo.baz.HasAGetValuesMethod;

public enum MysteryEnum implements HasAGetValuesMethod {

   THINGY, BOB;

   @Override
   public MysteryEnum[] getValues() {
      return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(MysteryEnum .class);
   }
}
</code></pre>

<p>In the getValues() method instead of simply calling <code>MysteryEnum.values()</code> it's using something called <code>sun.misc.SharedSecret</code> to get a handle to something called <code>sun.misc.JavaLangAccess</code>, then using <em>that</em> to get an array of all the enum values. The Javadoc on that class tells you what the method does, but I can't find much on <em>why</em> you would want to call it. </p>

<p>The developer that wrote this is no longer around, so I can't ask him. I'm going to ask my team anyway, but I have a feeling that the answer will be: "Don't know why it does that, but better not change it". For the moment, I'm assuming that this is either an odd case of someone not knowing that the <code>values()</code> method exists, or that my ignorance of the sun.misc libraries is causing me to miss something obvious to others. Any idea's why this code was written this way? </p>
