简体   繁体   中英

Java - Reflection how to find the type is enum

i try to find at run time the fully qualified type of the field type using reflection like the following.

if(! Modifier.isFinal(f.getModifiers()) && type.equals(Integer.class)){
                            f.set(clsObject, DefaultParamValuesEnum.INTEGER.getDefaultInt());

                    } 

when i try like the following for enum it gives exception :

else if(! Modifier.isFinal(f.getModifiers()) && type.equals(enum.class)){
                            f.set(clsObject,DefaultParamValuesEnum.LONGVALUE.getDefaultLong());  
                        }

following error i get:

Syntax error on token "enum", invalid 

How to figure out the enum type?

would some one help me on this please.

要检查类是否为枚举类型,只需使用Class.isEnum()

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