Java Class.getEnumConstants()
Syntax
Class.getEnumConstants() has the following syntax.
public T [] getEnumConstants()
Example
In the following code shows how to use Class.getEnumConstants() method.
//from w w w . j ava 2 s . c om
enum Programming {
java, python,
}
public class Main {
public static void main(String[] args) {
Class cls = Programming.class;
// returns the elements of this enum class
for (Object obj : cls.getEnumConstants()) {
System.out.println(obj);
}
}
}
The code above generates the following result.