[java] How to get all enum values in Java?

I came across this problem that I without knowing the actual enum type I need to iterate its possible values.

if (value instanceof Enum){
   Enum enumValue = (Enum)value;
}

Any ideas how to extract from enumValue its possible values ?

This question is related to java enums

The answer is


Object[] possibleValues = enumValue.getDeclaringClass().getEnumConstants();

Similar questions with java tag:

Similar questions with enums tag: