Class.getEnumConstants() has the following syntax.
public T [] getEnumConstants()
In the following code shows how to use Class.getEnumConstants() method.
// ww w . ja v a 2s . c o m 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.