title: Null Pointer Exception in Java Enum
body: <p>I'm learning Enum concept in java and I faced a problem while practicing. </p>
  
  <p>Here is the code snippet,</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyClass {
      private String cardColor = CARDS.SPADE.cardColor; #Causes Null Pointer #Default Value
      private MyClass(CARDS card){
          this.cardColor = card.cardColor;
      }
      public static enum CARDS{
          SPADE("Black"),
          CLUB("Black"),
          DIAMOND("Red"),
          HEART("Red");
          private String cardColor = null;
          private MyClass obj = null;
          CARDS(String color){
              this.cardColor = color;
              obj = new MyClass(this);         #Trying to create object for MyClass 
          }
          public String getCardColor(){
              return this.cardColor;
          }
      }
      public static void main(String args[]) {
          System.out.println(CARDS.SPADE);
      }
  }
  </code></pre>
  
  <p>I'm trying to create a MyClass object private to the enum in it's constructor. Here the value CARDS.SPADE is null and I end up with Null Pointer Exception.</p>
  
  <p>If I don't create an object in enum constructor everything works perfect,</p>
  
  <blockquote>
    <p>obj = new MyClass(this);</p>
  </blockquote>
  
  <p>I'm not understanding why the static enum is not initialized and I'm confused with the control flow here. Can someone explain me what's wrong here?</p>