title: class java.lang.Class cannot be cast to class java.lang.reflect.Parameterized
body: <p>Java 11</p>
  <p>I need to get generic type on runtime.</p>
  <p>Here client code:</p>
  <pre><code>     var dataTemplateClient = new DataTemplateJdbc&lt;Client&gt;(dbExecutor, entitySQLMetaDataClient); 
  
      public class Client {
          @Id
          private Long id;
          private String name;
      }
  </code></pre>
  <p>Here code:</p>
  <pre><code>import java.lang.reflect.ParameterizedType;
  import java.lang.reflect.Type;
  import java.sql.Connection;
  import java.util.Collections;
  import java.util.List;
  import java.util.Optional;
  
      public class DataTemplateJdbc&lt;T&gt; implements DataTemplate&lt;T&gt; {
          private final DbExecutor dbExecutor;
          private final EntitySQLMetaData entitySQLMetaData;
      
          public DataTemplateJdbc(DbExecutor dbExecutor, EntitySQLMetaData entitySQLMetaData) {
              this.dbExecutor = dbExecutor;
              this.entitySQLMetaData = entitySQLMetaData;
              ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
              Type type = genericSuperclass.getActualTypeArguments()[0];
          }
  </code></pre>
  <p>But I get error in this line:</p>
  <pre><code>ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
  </code></pre>
  <p>Error:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.ClassCastException: class java.lang.Class cannot be cast to class java.lang.reflect.ParameterizedType (java.lang.Class and java.lang.reflect.ParameterizedType are in module java.base of loader 'bootstrap')
      at mypackage.DataTemplateJdbc.&lt;init&gt;(DataTemplateJdbc.java:26)
  </code></pre>