title: How to write a method that can return different data type based on enum as the parameter?
body: <p>I would like to define a method and by passing the enum, returns the mapped type based on the enum. So far I only work out this way:</p>
  
  <pre><code>public class Person {
  
      HashMap&lt;String, Object&gt; mData;
  
  
      void int getDetail(DetailInt detail){
          Object data = mData.get(detail.name());
          if(data instanceof Integer)
              return (int)data;
          return 0;
      }
  
      void String getDetail(DetailStr detail){
          Object data = mData.get(detail.name());
          if(data instanceof String)
              return (String)data;
          return "";
      }
  
  }
  
  
  
  public enum DetailInt {
      Age("age"), Weight("weight"), Height("height");
  
      String columnName;
      DetailInt(String columnName){
          this.columnName= columnName;
      }
  }
  
  public enum DetailStr {
      FirstName("first_name"), LastName("last_name");
  
      String columnName;
      DetailStr (String columnName){
          this.columnName= columnName;
      }
  }
  </code></pre>
  
  <p>So I can use the same method, but passing different enums to get the data with the type.</p>
  
  <pre><code>int age = person.getDetail(DetailInt.Age);
  String firstName = person.getDetail(DetailStr.FirstName);
  </code></pre>
  
  <p>Now, what I would like to achieve is to merge both enums together, so I can call as below:</p>
  
  <pre><code>int age = person.getDetail(Detail.Age);
  String firstName = person.getDetail(Detail.FirstName);
  </code></pre>
  
  <p>It is neater. However, I have tried generic type and interface, still cannot find the way to do it. Use below way is similar to what I want but this is not enum type.</p>
  
  <pre><code>abstract class Detail {
  
  }
  
  class DetailStr extend Detail {
  
  }
  
  interface Details {
      DetailStr firstName = new DetailStr("first_name");
      DetailStr lastName = new DetailStr("las_name");
      DetailInt age = new DetailInt("age");
      DetailInt weight = new DetailInt("weight");
      DetailInt height = new DetailInt("height");
  }
  
  public class Person {
  
      void int getDetail(DetailInt detail){
          ....
      }
  
      void String getDetail(DetailStr detail){
          ....
      }
  
  }
  </code></pre>