title: Java - How to pass a Generic parameter as Class<T> to a constructor
body: <p>I have a problem here that still cannot solve, the thing is I have this abstract class:</p>
  
  <pre><code>public abstract class AbstractBean&lt;T&gt; {
      private Class&lt;T&gt; entityClass;
  
      public AbstractBean(Class&lt;T&gt; entityClass) {
          this.entityClass = entityClass;
      }
      ...
  }
  </code></pre>
  
  <p>Now I have another class that inherits this abstract:</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class BasicUserBean&lt;T extends BasicUser&gt; extends AbstractBean&lt;T&gt;  {
      private Class&lt;T&gt; user;    
  
      public BasicUserBean() {  
          super(user);  // Error: cannot reference user before supertype contructor has been called.
      }
  }
  </code></pre>
  
  <p>My question is how can I make this to work?, I am trying to make the class <strong>BasicUserBean</strong> inheritable, so if I have class <strong>PersonBean</strong> which inherits <strong>BasicUserBean</strong> then I could set in the Generic the entity <strong>Person</strong> which also inherits the entity <strong>BasicUser</strong>. And it will end up being:</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class PersonBean extends BasicUserBean&lt;Person&gt;  {
  
      public PersonBean() {
          super(Person.class);
      }
      ...
  }
  </code></pre>
  
  <p>I just want to inherit the basic functionality from BasicUserBean to all descendants, so I do not have to repeat the same code among all descendants. Thanks!.</p>