-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumTest.java
More file actions
56 lines (45 loc) · 1.25 KB
/
EnumTest.java
File metadata and controls
56 lines (45 loc) · 1.25 KB
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package foundation.enumTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;
/**
* User: gaozhan
* Date: 9/12/13
* Time: 2:33 PM
* To change this template use File | Settings | File Templates.
*/
public class EnumTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
System.out.println(Color.RED);
}
enum Color{
RED(255,0,2),BLUE(0,0,255),BLACK(0,0,0),YELLOW(255,255,0),GREEN(0,255,0);
//构造枚举值,比如RED(255,0,0)
private Color(int rv,int gv,int bv){
this.redValue=rv;
this.greenValue=gv;
this.blueValue=bv;
}
public String toString(){ //覆盖了父类Enum的toString()
return super.toString()+"("+redValue+","+greenValue+","+blueValue+")";
}
private int redValue; //自定义数据域,private为了封装。
private int greenValue;
private int blueValue;
}
enum WeekDay {
Mon("first"),Tue("second");
private WeekDay(String str) {
content = str;
}
private String content;
}
}