title: Enum Base Classes in Java
body: <p>What is the best way to use this as a base class for an Enum like class. I would like to be able to create different concrete types without having to re-code the getter methods.</p>
  
  <pre><code>public enum Tool extends Item
  {
      Pickaxe("Pickaxe", 101),
      Saw("Saw", 201);
  }
  </code></pre>
  
  <p>And Tool.getNames() would return a list of all the Item names in the Tool class.</p>
  
  <pre><code>public enum Item
  {
      Default("Name", 0);
  
      private final int id;
      private final String name;
  
      Item(String name, int id)
      {
          this.id = id;
          this.name = name;
      }
  
      public int getId()
      {
          return this.id;
      }
  
      public int[] getIds()
      {
          Item[] items = Item.values();
          int[] ids = new int[items.length];
          for (int i = 0; i &lt; items.length; i++)
          {
              ids[i] = items[i].getId();
          }
          return ids;
      }
  
      public String getName()
      {
          return this.name;
      }
  
      public String[] getNames()
      {
          Item[] items = Item.values();
          String[] names = new String[items.length];
          for (int i = 0; i &lt; items.length; i++)
          {
              names[i] = items[i].getName();
          }
          return names;
      }
  }
  </code></pre>
  
  <p>I know it isn't possible like this, but how could I approach this situation? I'd like to be able to access the members of each class just like you would an enum: Tool.Pickaxe.</p>