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);
}
}
}
請問爲什麼?什麼是正確的解決方案與泛型?