title: Getting the class name from a generic static method in Java
body: <p>I have a code:</p>
  
  <p>Model.java:</p>
  
  <pre><code>public abstract class Model &lt;T&gt; {
    public static &lt;T&gt; T find(int id) {
      T result = (T) blackMagicMethod(T.class, id);
  
      return result;
    }
  }
  </code></pre>
  
  <p>, User.java</p>
  
  <pre><code>public class User extends Model&lt;User&gt; {
  }
  </code></pre>
  
  <p>, Main.java:</p>
  
  <pre><code>public class Main {
    public static void main(String[] args) {
      System.out.println(User.find(1));
    }
  }
  </code></pre>
  
  <p>, blackMagicMethod: </p>
  
  <pre><code>public Object blackMagicMethod(Class clazz, int id) {}
  </code></pre>
  
  <p>The line <code>blackMagicMethod(T.class, id)</code> don't work, like any hacks described in <a href="https://stackoverflow.com/questions/936684/getting-the-class-name-from-a-static-method-in-java">Getting the class name from a static method in Java</a>.</p>
  
  <p>How can I make this code working?</p>