我有一个 Actor 的概率
JAXBElement<User> jaxbElement = (JAXBElement<User>)unmarshaller.unmarshal(sr);
这是行不通的,大家可以帮帮我吗?
我不能这样做: 我给你看我的代码:
StringReader sr = new StringReader(this.message);
JAXBElement<Utilisateur> jaxbElement = (JAXBElement<Utilisateur>) unmarshaller.unmarshal(sr);
如果我这样做,我会出错,因为我使用了 StringReader :
JAXBElement<User> jaxbElement = unmarshaller.unmarshal(sr, User.class);
最佳答案
如果您想避免编译器警告,您可以使用一种采用 Class
参数的解码方法。
JAXBElement<User> jaxbElement = unmarshaller.unmarshal(sr, User.class);
注意
您的代码应该运行得非常好,因为您在问题中使用了它。
关于java - 类型安全 : Unchecked cast from Object to JAXBElement<User>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23312053/