Get declared methods for enum class : Enum « Reflection « Java






Get declared methods for enum class


import java.lang.reflect.Method;

import org.xml.sax.XMLReader;

public class GetMethod {

  public static void main(String[] args) {
    Method[] ms = String.class.getMethods();
    for (int i = 0; i < ms.length; i++) {
      // System.out.println(ms[i].getName());
    }
    Method[] ims = XMLReader.class.getMethods();
    for (int i = 0; i < ims.length; i++) {
      // System.out.println(ims[i].getName());
    }
    Method[] sms = Size.class.getMethods();
    for (int i = 0; i < sms.length; i++) {
      // System.out.println(sms[i].getName());
    }
    String pc = new String();
    try {
      Method setCpu = String.class.getMethod("toString", String.class);
      setCpu.invoke(pc, "Intel 3.0");
      System.out.println(pc.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

enum Size {
  S, M, L, XL, XXL, XXXL;

}

 








Related examples in the same category

1.Is it an enum
2.Deal with Enum Type in reflection
3.Enum type as class
4.Enum Spy
5.Deal with enum type and its method
6.Deal with enum type field
7.Get and set value of a Enum type field