枚舉示例程序
?
?1
public
?
class
?EnumTest?
{
?2
?3
????
public
?
enum
?MsgType?
{
?4
????????SMS(
"
this?sms
"
),?LONGSMS(
"
this?is?longsms
"
),?MMS(
"
this?is?mms
"
),?WAP_PUSH(
"
this?is?wap?push
"
);
?5
????????
private
?
final
?String?index;
?6
?7
????????
private
?MsgType(String?index)?
{
?8
????????????
this
.index?
=
?index;
?9
????????}
10
11
????????
/**/
/*
public?int?getIndex()?{
12
????????????return?index;
13
????????}
*/
14
15
????????
//
下面這段基本上不用
16
????????
public
?
static
?MsgType?getType(
int
?index)?
{
17
????????????
switch
?(index)?
{
18
????????????
case
?
0
:
19
????????????????
return
?SMS;
20
????????????
case
?
1
:
21
????????????????
return
?LONGSMS;
22
????????????
case
?
2
:
23
????????????????
return
?MMS;
24
????????????
case
?
3
:
25
????????????????
return
?WAP_PUSH;
26
????????????
default
:
27
????????????????
return
?SMS;
28
????????????}
29
????????}
30
????}
31
????
32
????
33
????
public
?
static
?
void
?main(String?[]args)
{
34
????????System.out.println(MsgType.SMS);
35
????????System.out.println(MsgType.getType(
0
));
36
????}
37
}
38



?2

?3



?4

?5

?6

?7



?8

?9

10

11


12

13

14

15

16



17



18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33



34

35

36

37

38

posted on 2011-05-23 15:43 tobyxiong 閱讀(242) 評(píng)論(0) 編輯 收藏 所屬分類: java