KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In C# I can do actually this: //This is C# static T SomeMethod<T>() where T:new() { Console.WriteLine("Typeof T: "+typeof(T)); return new T(); } //And call the method here SomeMethod<SomeClassName>(); But for some reason I can't get it to work in Java. The thing I want to do is, to create a static method on a superclass, so the subclasses can be converted to XML. //This is Java, but doesn't work public static T fromXml<T>(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<SomeSubObject>("<xml/>");
Tags (comma-separated)
Save Edits
Cancel