title: Is it possible to extend enum in Java 8?
body: <p>Just playing and came up with a sweet way to add functionality to <code>enum</code>s in <a href="https://stackoverflow.com/q/22074497/823393">Java Enum toString() method</a> with <a href="https://stackoverflow.com/a/22075272/823393">this</a>.</p>
  
  <p>Some further tinkering allowed me to <em>nearly</em> also add a tidy (i.e. not throwing an exception) reverse look-up but there's a problem. It's reporting:</p>
  
  <pre><code>error: valueOf(String) in X cannot implement valueOf(String) in HasValue
  public enum X implements PoliteEnum, ReverseLookup {
  overriding method is static
  </code></pre>
  
  <p>Is there a way?</p>
  
  <p>The aim here is to silently add (via an interface implementation with a <code>default</code> method like I added <code>politeName</code> in the linked answer) a <code>lookup</code> method that does the <code>valueOf</code> function without throwing an exception. Is it possible? It is clearly now possible to extend <code>enum</code> - one of my major problems with Java until now.</p>
  
  <p>Here's my failed attempt:</p>
  
  <pre><code>public interface HasName {
  
      public String name();
  }
  
  public interface PoliteEnum extends HasName {
  
      default String politeName() {
          return name().replace("_", " ");
      }
  }
  
  public interface Lookup&lt;P, Q&gt; {
  
      public Q lookup(P p);
  }
  
  public interface HasValue {
      HasValue valueOf(String name);
  }
  
  public interface ReverseLookup extends HasValue, Lookup&lt;String, HasValue&gt; {
  
      @Override
      default HasValue lookup(String from) {
          try {
              return valueOf(from);
          } catch (IllegalArgumentException e) {
              return null;
          }
      }
  
  }
  
  public enum X implements PoliteEnum/* NOT ALLOWED :( , ReverseLookup*/ {
  
      A_For_Ism, B_For_Mutton, C_Forth_Highlanders;
  }
  
  public void test() {
      // Test the politeName
      for (X x : X.values()) {
          System.out.println(x.politeName());
      }
      // ToDo: Test lookup
  }
  </code></pre>