Checking if a class is java.lang.Enum

The correct syntax would be:

Enum.class.isAssignableFrom(test.MyEnum.class)

but for enums, here is a more convenient method:

if (someObject.getClass().isEnum()))

Update: for enum items with a body (e. g. that override methods), this won’t actually work.
In that case, use

if (someObject instanceof Enum<?>)

Reference:

  • Class.isEnum()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)