title: Generic method in Java without generic argument
body: <p>In C# I can do actually this:</p>
  
  <pre><code>//This is C#
  static T SomeMethod&lt;T&gt;() where T:new()
  {
    Console.WriteLine("Typeof T: "+typeof(T));
    return new T();
  }
  
  //And call the method here
  SomeMethod&lt;SomeClassName&gt;();
  </code></pre>
  
  <p>But for some reason I can't get it to work in Java. </p>
  
  <p>The thing I want to do is, to create a static method on a superclass, so the subclasses can be converted to XML.</p>
  
  <pre><code>//This is Java, but doesn't work
  public static T fromXml&lt;T&gt;(String xml) {
    try {
      JAXBContext context = JAXBContext.newInstance(T.class);
      Unmarshaller um = context.createUnmarshaller();
      return (T)um.unmarshal(new StringReader(xml));
    } catch (JAXBException je) {
      throw new RuntimeException("Error interpreting XML response", je);
    }
  }
  
  //Also the call doesn't work...
  fromXml&lt;SomeSubObject&gt;("&lt;xml/&gt;");
  </code></pre>