title: Generic class - getClass().getName()
body: <p>I have a generic base class:</p>
  
  <pre><code>public class BaseLabel&lt;T&gt; extends JXLabel {
      private static final long serialVersionUID = 1L;
  
      public BaseLabel() {
          System.out.println(T.class.getClass().getName()); //error
      }       
  }
  </code></pre>
  
  <p>and Child class:</p>
  
  <pre><code>public class ChildLabel extends BaseLabel&lt;ChildLabel&gt; {
      private static final long serialVersionUID = 2L;
  
      public ChildLabel() {
  
      }       
  }
  </code></pre>
  
  <p>I am getting compilation error.</p>
  
  <p>Is there any way to get the actual class name from the constructor of BaseClass. Here, by actual class I am referring to that class, which I am going to instantiate.</p>
  
  <p>For example I am instantiating ChildClass, <code>ChildClass clz = new ChildClass()</code>;</p>
  
  <p>then that <code>println()</code> will print <code>package.ChildClass</code>.</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>The compilation error is:</p>
  
  <pre><code>cannot select from a type variable System.out.println(T.class.getClass().getSimpleName());
  </code></pre>
  
  <hr>
  
  <p>If I call <code>this.getClass.getSimpleName()</code> from the <code>abstract BaseClass</code>'s constructor. It is printing the <code>ChildClass</code>. </p>
  
  <p>Why?</p>
  
  <p>Is it due to, as I am instantiating <code>ChildClass</code> so this is pointing to the <code>ChildClass</code>'s object.</p>