Skip to content

Commit d5a48a5

Browse files
author
yuki
committed
[wip]ch 19
1 parent e35b083 commit d5a48a5

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/java/code/ch19/EnumClass.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package code.ch19;
2+
3+
/**
4+
* @author yuzhe
5+
* @since 10/18/18
6+
*/
7+
/**
8+
* @author yuzhe
9+
* @since 10/18/18
10+
*/
11+
12+
enum Shrubbery {
13+
GROUND,
14+
CRAWLING,
15+
HANGING
16+
}
17+
18+
public class EnumClass {
19+
20+
public static void main(String[] args) {
21+
for (Shrubbery s : Shrubbery.values()) {
22+
System.out.println(s + ".ordinal = " + s.ordinal());
23+
System.out.println(s + ".compareTo(" + Shrubbery.GROUND + ") = " + s.compareTo(Shrubbery.GROUND));
24+
System.out.println(s + " == " + Shrubbery.HANGING + " = " + (s == Shrubbery.HANGING));
25+
System.out.println(s.getDeclaringClass());
26+
System.out.println(s.name());
27+
System.out.println("--------------------------------------");
28+
}
29+
for (String s : "GROUND CRAWLING HANGING".split(" ")) {
30+
Shrubbery shrubbery = Shrubbery.valueOf(s);
31+
System.out.println(shrubbery);
32+
}
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)