Skip to content

Commit 6372f78

Browse files
author
xiachaochao
committed
123
1 parent 283eee7 commit 6372f78

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.xinan.enum1;
2+
3+
public enum Enum1 {
4+
5+
MON("周一", 18) {
6+
7+
@Override
8+
public boolean isRest() {
9+
System.out.println("修改过的");
10+
return true;
11+
}
12+
},
13+
TUE("周一", 19), WED("周一", 20), THU("hello3", 25), FRI("hello4", 27), SAT("hello5", 18), SUN("hello6", 18);
14+
private String name;
15+
private int age;
16+
17+
private Enum1(String name, int age) {
18+
this.name = name;
19+
this.age = age;
20+
}
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
public int getAge() {
31+
return age;
32+
}
33+
34+
public String setAge(int age) {
35+
this.age = age;
36+
return "修改年龄";
37+
}
38+
39+
public boolean isRest() {
40+
System.out.println("默认");
41+
return false;
42+
}
43+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.xinan.enum1;
2+
3+
public class Enum1Test {
4+
public static void main(String[] args) {
5+
for (Enum1 e1 : Enum1.values()) {
6+
System.out.println(e1.getAge()+" "+e1.getName());
7+
}
8+
Enum1.MON.isRest();
9+
Enum1.TUE.isRest();
10+
//System.out.println(Enum1.MON.valueOf("3"));
11+
System.out.println(Enum1.TUE.getAge());
12+
System.out.println(Enum1.TUE.setAge(20));
13+
System.out.println(Enum1.TUE.getAge());//???????????????
14+
}
15+
}

0 commit comments

Comments
 (0)