package enumtest1;
public class enumtest {
//定义JAVA枚举类型
enum Test
{
test1,test2,test3,test4
}
public static void testmethon(Test t)
{
switch (t)
{
case test1:
System.out.println(t);
break;
case test2:
System.out.println(t);
break;
case test3:
System.out.println(t);
break;
case test4:
System.out.println(t);
break;
}
}
public static void main(String[] args)
{
System.out.println(Test.test1);
//values() 获取所有枚举类型
for (Test s:Test.values())
{
//使用ordinal() 可以获取枚举申明顺序数组
System.out.println(s.ordinal());
}
Test t = Test.test1;
testmethon(t);
}
}
//结果
test1
0
1
2
3
test1
网友评论