How to find out if a field is instanceof a type via reflection?

后端 未结 4 1196
不知归路
不知归路 2020-12-24 04:32

I want to find out via reflection if a field is an instance of some type T.

Lets say I have an object o. Now I want to know if it has any

4条回答
  •  孤独总比滥情好
    2020-12-24 05:29

    If you want to compare the field type of a custom class you should try this, use .class because only primitive types has .TYPE.

    if(field.getType().isAssignableFrom(**YOURCLASS.class**)){}

提交回复
热议问题