[英]Getting a methods Return type via reflection
I am getting the attributes from an incoming object which I will check it's values. 我从传入的对象获取属性,我将检查其值。
I wish to know if there is a way via reflection that I can obtain not only the value from attribute but also it's type? 我想知道是否有一种通过反射的方法,我不仅可以从属性中获取值,还可以获取其类型?
would 将
result instanceof Integer.Class
work for example? 例如工作?
This should be the safest and most universal way. 这应该是最安全,最通用的方法。 It's null-safe, you don't need an extra != null check:
这是空值安全的,您不需要额外的!=空值检查:
SomeClass.class.isInstance(result)
Reference: 参考:
您可以使用result.getClass()
No. 没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.