title: Generic method without type argument
body: <p>I was wondering if there's a way to, in Java, use a generic type within a generic method without requiring an argument specifying the class type. Here's the normal way of doing it:</p>
  
  <pre><code>public &lt;T&gt; T doSomethingGeneric(Class&lt;T&gt; type, int a) {
      return (T) doSomethingElse(type, a);
  }
  </code></pre>
  
  <p>I would like this as an alternative:</p>
  
  <pre><code>public &lt;T&gt; T doSomethingGeneric(int a) {
      return (T) doSomethingElse(/* some magic with T here */, a);
  }
  </code></pre>
  
  <p>Background: I'm writing utility methods with Hibernate. Here's an example of what I'm actually trying to do, and you can infer how it applies to this problem.</p>
  
  <pre><code>public static &lt;M extends Model&gt; M get(Class&lt;M&gt; type, Serializable id) {
      Session session = newSession();
      Transaction t = session.beginTransaction();
      Object model = null;
      try {
          model = session.get(type, id);
          t.commit();
      } catch (HibernateException ex) {
          t.rollback();
          throw ex;
      }
      return (M) model;
  }
  </code></pre>
  
  <p>Is this possible? If so, how is it done? Thanks!</p>