Checking if a class is java.lang.Enum

后端 未结 2 1407
逝去的感伤
逝去的感伤 2021-02-01 11:49

I\'m trying to know if a class is an Enum, but I think I\'m missing something:

if (test.MyEnum.class instanceof Enum.class)
 obj = resultWrapper.getEnum         


        
2条回答
  •  滥情空心
    2021-02-01 12:45

    If you're talking about Java 5 new feature - enum (it's not very new actually), then this is the way to go:

    if (obj.getClass().isEnum()) {
    
    ...
    }
    

    If Enum is your custom class, then just check that obj instanceof Enum.

提交回复
热议问题