Java中Enum方法toString与ordinal方法
public enum Language { C, Java, PHP; } public class EnumDemo { public static void main(String args[]) { // returns the name of this enum constant(String) System.out.println("Programming in " + Language.C.toString()); System.out.println("Programming in " + Language.Java.toString()); System.out.println("Programming in " + Language.PHP.toString()); // returns the ordinal of this enum constant,start with 0 (int) System.out.println("Programming in " + Language.C.ordinal()); System.out.println("Programming in " + Language.Java.ordinal()); System.out.println("Programming in " + Language.PHP.ordinal()); } }