title: How to create an instance of enum using reflection in Java?
body: <p>When I'm reading <em>Effective Java</em>, the author told me that a single-element <code>enum</code> type is the best way to implement a singleton, because we don't have to consider sophisticated serialization or reflection attacks. This means we cannot create an instance of <code>enum</code> using reflection, right?</p>
  
  <p>I have done some tests, with an <code>enum</code> class here:</p>
  
  <pre><code>public enum Weekday {}
  </code></pre>
  
  <p>Then I tried to create an instance of <code>Weekday</code>:</p>
  
  <pre><code>Class&lt;Weekday&gt; weekdayClass = Weekday.class;
  Constructor&lt;Weekday&gt; cw = weekdayClass.getConstructor(null);
  cw.setAccessible(true);
  cw.newInstance(null);
  </code></pre>
  
  <p>As you know, it doesn't work. When I change the key word <code>enum</code> to <code>class</code>, it works. I want to know why. Thank you.</p>