开发者

Getting a methods Return type via reflection

开发者 https://www.devze.com 2023-03-31 14:06 出处:网络
I am getting the attributes from an 开发者_JAVA百科incoming object which I will check it\'s values.

I am getting the attributes from an 开发者_JAVA百科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:

Class.isInstance(Object)


You can use result.getClass()


No.

Use Class.isAssignableFrom()

0

精彩评论

暂无评论...
验证码 换一张
取 消