简体   繁体   中英

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:

Class.isInstance(Object)

您可以使用result.getClass()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM