如何将对象转换为 getClass() 返回的类
ProtostuffIOUtil.mergeFrom(data,o,RuntimeSchema.getSchema(o.getClass()));
如何将 Object 转换为 getClass() 类。通过上面的方法调用,我会得到一个编译错误,因为该方法要求 o 变量与 o.getClass() 参数属于同一类。如何解决这个问题?
ProtostuffIOUtil.mergeFrom(data,o,RuntimeSchema.getSchema(o.getClass()));
How to cast Object to getClass() Class. With the above method call, I will get a compile error because the method requires that the o variable is of the same class as the o.getClass() parameter. How does one get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用cast()方法将对象从getClass()转换为类:
myObj.getClass().cast(myObj)
Cast an object to the class from getClass() using the cast() method:
myObj.getClass().cast(myObj)