title: Java generics question - Class<T> vs. T?
body: <p>I'm using Hibernate validator and trying to create a little util class:</p>
  
  <pre><code>public class DataRecordValidator&lt;T&gt; {
      public void validate(Class&lt;T&gt; clazz, T validateMe) {
          ClassValidator&lt;T&gt; validator = new ClassValidator&lt;T&gt;(clazz);
          InvalidValue[] errors = validator.getInvalidValues(validateMe);
          [...]
      }
  }
  </code></pre>
  
  <p>Question is, why do I need to supply the <code>Class&lt;T&gt; clazz</code> parameter when executing <code>new ClassValidator&lt;T&gt;(clazz)</code>?  Why can't you specify:</p>
  
  <ol>
  <li><code>T</code> as in <code>ClassValidator&lt;T&gt;(T)</code>?  </li>
  <li><code>validateMe.getClass()</code> as in <code>ClassValidator&lt;T&gt;(validateMe.getClass())</code></li>
  </ol>
  
  <p>I get errors when I try to do both options.</p>
  
  <p><em>Edit</em>: I understand why #1 doesn't work.  But I don't get why #2 doesn't work.  I currently get this error with #2: </p>
  
  <pre><code>cannot find symbol
  symbol  : constructor ClassValidator(java.lang.Class&lt;capture#279 of ? extends java.lang.Object&gt;)
  location: class org.hibernate.validator.ClassValidator&lt;T&gt;
  </code></pre>
  
  <p>Note: Hibernate API method is (<a href="http://www.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.3.0.cp03_fp01/api/hibernate-validator/org/hibernate/validator/ClassValidator.html" rel="noreferrer">here</a>)</p>