title: Java: an enum in an extending class
body: <p>I have a class that extends another one. It should have an enum that should have certain values for the extending class, so I have the following:</p>
  
  <pre><code>public class Shepherd extends Dog {
  
      public enum Color {
          BLACK,
          GREEN,
          INVISIBLE
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>This enum should be a part of the extending class, as another class that extends <code>Dog</code> should have its own enum with its own values, that's why I can't make the <code>Color</code> enum a part of the <code>Dog</code> class. For example:</p>
  
  <pre><code>public class Corgi extends Dog {
  
      public enum Color {
          RED,
          BLACK,
          SABLE
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>Also, I have a constructor:</p>
  
  <pre><code>public class Shepherd extends Dog {
  
      public enum Color {
          // ...
      }
  
      public Shepherd(Color color) {
          super(color);
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>I need the base class (<code>Dog</code>) to have the <code>color</code> field that would be accessible from other methods of the same base class (<code>Dog</code>).</p>
  
  <pre><code>public class Dog {
  
      public enum Color { } // not sure in that :-(
  
      private Color color;
  
      public Dog(Color color) {
          this.color = color;
      }
  
      public Color getColor() {
          return this.color;
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>Obviously, it won't work, as <code>Dog.Color</code> is not the same type as <code>Shepherd.Color</code>. OK, let's do it another way:</p>
  
  <pre><code>public class Shepherd extends Dog&lt;Shepherd&gt; {
  
      // ...
  
      public Shepherd(Color color) {
          super(color);
      }
  
      // ...
  
  }
  </code></pre>
  
  <pre><code>public class Dog&lt;T extends Dog&gt; {
  
      public enum Color { } // ???
  
      private T.Color color;
  
      public Dog(T.Color color) {
          this.color = color;
      }
  
      public T.Color getColor() {
          return this.color;
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>And I'm still getting <code>incompatible types: Shepherd.Color cannot be converted to Dog.Color</code>. :-( Why doesn't Java accept it? The parameter has type <code>T.Color</code>, which should mean <code>Shepherd.Color</code> or <code>Corgi.Color</code> dependent on the class we use, isn't it?</p>
  
  <p>Would anyone be so kind as to show me the correct way with an example? Thanks in advance!</p>