title: How to get the generic type at runtime?
body: <p>This is my code:
  The ExecutorImp extends AbstractExecutor which extract the same execute logics of its implementers(ExecutorImp is one case),when calling the execute() method of ExecutorImp, it will call the method in its supertype,but the supertype (the AbstractExcutor) should know another class binding to the implementer(in the example, it is the User class):</p>
  
  <pre><code>import java.lang.reflect.InvocationTargetException;
  import java.util.ArrayList;
  
  abstract class AbstractExecutor&lt;E&gt; {
      public void execute() throws Exception {
          ArrayList&lt;E&gt; list = new ArrayList&lt;E&gt;();
          // here I want to get the real type of 'E'
          Class cl = this.getClass().getTypeParameters()[0].getGenericDeclaration().getClass();
          Object o = cl.getConstructor(String.class).newInstance("Gate");
          list.add((E) o);
          System.out.println(format(list));
      }
      public abstract String format(ArrayList&lt;E&gt; list);
      public abstract String getType();
  }
  
  public class ExectorImp&lt;E&gt; extends AbstractExecutor&lt;User&gt; {
      @Override
      public String getType() {
          return "user";
      }
      @Override
      public String format(ArrayList&lt;User&gt; list) {
          StringBuffer sb = new StringBuffer();
          for (User u : list) {
              sb.append(u.toString() + " ");
          }
          return sb.toString();
      }
      public static void main(String[] args) throws Exception {
          new ExectorImp().execute();
      }
  }
  class User {
      String name;
      public User(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>SO, what is the problem with my codes?</p>