package enumTest;java
import java.util.EnumMap;ide
import java.util.EnumSet;this
import java.util.Iterator;.net
import java.util.Map.Entry;code
interface A1 {element
void isRest();
}get
enum Test2 implements A1 {it
MON("一", 1), TUE("二", 2), FRI("三", 3) { [@Override](https://my.oschina.net/u/1162528) public void isRest() { // TODO Auto-generated method stub System.out.println("today is " + FRI.name + "休息"); } }; private String name; private int id; private Test2() { } private Test2(String name, int id) { this.name = name; this.id = id; } [@Override](https://my.oschina.net/u/1162528) public void isRest() { // TODO Auto-generated method stub } /* abstract void isOpen(); */
}class
public class Test1 {import
public static void main(String[] args) { // public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType) // 建立一個包含指定元素類型的全部元素的枚舉 set。 EnumSet<Test2> TestSet = EnumSet.allOf(Test2.class); for (Enum<Test2> enum1 : TestSet) { System.out.println(enum1); /* * MON TUE FRI */ } EnumMap<Test2, String> Map = new EnumMap<>(Test2.class); Map.put(Test2.TUE, "ss"); for (Iterator<Entry<Test2, String>> iter = Map.entrySet().iterator(); iter.hasNext();) { Entry<Test2, String> entry = iter.next(); System.out.println(entry.getKey() + ":" + entry.getValue()); } }
}