Package COM. XX. tests; import Java. util. hashmap; import Java. util. map; Public Enum season {spring {@ overridepublic string tostring () {return "Spring" ;}}, summer {@ overridepublic string tostring () {return "Summer ";}}, autumn {@ overridepublic string tostring () {return "Autumn" ;}}, winter {@ overridepublic string tostring () {return "Winter ";}}; private Static final map <integer, season> lookup = new hashmap <integer, season> (); static {for (season SE: season. values () {lookup. put (SE. ordinal (), se) ;}} public static season fromordinal (INT idx) {return lookup. get (idx );}}
Package COM. XX. tests; import Java. util. enumset; import Org. JUnit. test; public class testseason {@ testpublic void test () {season sea = season. spring; system. out. println (SEA); For (season S: season. values () {system. out. println (s); system. out. println (S. ordinal ();} system. out. println ("#######"); Season S1 = enum. valueof (season. class, "Spring"); system. out. println (S1); system. out. println ("#######"); system. out. println (season. fromordinal (3); system. out. println ("#######"); enumset <season> es = enumset. allof (season. class); For (season: ES) {system. out. println (season);} system. out. println ("#######"); enumset <season> ES2 = enumset. of (season. autumn, season. winter); For (season: ES2) {system. out. println (season );}}}