title: How to match compiled class name to an enum member in Java?
body: <p>In Java, with Sun's JDK 1.6, with an enum such as this:</p>
  
  <pre><code>public enum MyEnum {
      FIRST_MEMBER { public void foo() { } },
      SECOND_MEMBER { public void foo() { } }, 
      THIRD_MEMBER { public void foo() { } };
  }
  </code></pre>
  
  <p>The compiled files are:  </p>
  
  <pre><code>MyEnum$1.class  MyEnum$2.class  MyEnum$3.class  MyEnum.class 
  </code></pre>
  
  <p>This also means that a stack trace showing <code>foo()</code>, or the method call printed in JVisualVM, etc., will have something like this at the top:</p>
  
  <pre><code>mypackage.MyEnum$1.run()
  </code></pre>
  
  <p>The <code>$1</code> in the class name is due to the members of the enum being compiled to anonymous inner classes. I am wondering if it is safe to assume that the numbers used in these class names map to the order in which the enum members are defined? If it is not, is there a standard, guaranteed way to find the enum member from the number used as the anonymous class name?</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>In regards to the design of the enum, this was used for illustration purposes only. The real enum implements an interface, and each member provides a different implementation of the methods. Please don't pay too much attention to what admittedly looks a bit strange. </p>
  
  <hr>
  
  <p>EDIT #2</p>
  
  <p>To clarify, I am not trying to do anything with this information <em>programmatically</em> (such as weird reflection nonsense). Rather, I am looking at stack traces and profiling information, and trying to map a method call on an enum member (shown as a call on an anonymous class) against the actual enum member in the source code.</p>