如何将对象转换为getClass()返回的类, [英] How to cast an object to the class returned by getClass()

查看:368
本文介绍了如何将对象转换为getClass()返回的类,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ProtostuffIOUtil.mergeFrom(data,o,RuntimeSchema.getSchema(o.getClass()));

如何将Object转换为getClass()类。使用上面的方法调用,我将得到一个编译错误,因为该方法要求o变量是与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?

推荐答案

Class clazz = o.getClass();
ProtostuffIOUtil.mergeFrom(data, clazz.cast(o), RuntimeSchema.getSchema(clazz));

这篇关于如何将对象转换为getClass()返回的类,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆