Java Questions
Java Questions

Reputation: 7963

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.

Upvotes: 1

Views: 131

Answers (1)

NilsH
NilsH

Reputation: 13831

To check if a class is of enum type, simply use Class.isEnum()

Upvotes: 9

Related Questions