0
在我的示例JAXBContext.newInstance(T)
需要参数类和此泛型解决方案不起作用。如何在参数中使用泛型需要类
public class SerializationUtilJaxb<T> {
public String serialize(T jaxbObject) {
StringWriter stringWriter = new StringWriter();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(T);
Marshaller objectMarshaller = jaxbContext.createMarshaller();
objectMarshaller.marshal(jaxbObject, stringWriter);
return stringWriter.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
}
请问为什么?什么是正确的解决方案与泛型?