Java Reflection - Java Class.getEnumConstants()


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()) {

The code above generates the following result.