File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ name: EARTH
2
+ ordinal: 0
3
+ toString: EARTH
4
+ Values class: class [LA;
5
+ MONDAY : 0
6
+ TUESDAY : 1
7
+ SATURDAY : 2
8
+ Stuff : 3
9
+ By-name value: MONDAY
10
+ Correctly failed to retrieve illegal name, message: key not found: stuff
Original file line number Diff line number Diff line change
1
+ class JEnum {
2
+ def name : String = " Foo"
3
+ def ordinal : Int = 10
4
+ def action = " fofofo"
5
+ }
6
+
7
+ enum A extends JEnum {
8
+ case MONDAY , TUESDAY , SATURDAY
9
+ case Stuff
10
+ case Someday (x : String )
11
+ def report = " Reported"
12
+ }
13
+
14
+ trait Foo1
15
+ trait Bar
16
+
17
+ enum B (val gravity : Double )(val isItGood : Boolean ) extends Foo1 {
18
+ case EARTH extends B (9.8 )(true )
19
+ case JUPITER extends B (100 )(true )
20
+ case MOON extends B (4.3 )(true )
21
+ case Foo extends B (10 )(true ) with Bar
22
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def main (args : Array [String ]): Unit = {
3
+ val t1 = B .EARTH
4
+ val t2 = B .JUPITER
5
+
6
+ println(" name: " + t1.name)
7
+ println(" ordinal: " + t1.ordinal)
8
+ println(" toString: " + t1.toString)
9
+
10
+ val values : Array [A ] = A .values
11
+ println(" Values class: " + values.getClass)
12
+ values.foreach(v => println(v.name + " : " + v.ordinal))
13
+ println(" By-name value: " + A .valueOf(" MONDAY" ))
14
+ try A .valueOf(" stuff" )
15
+ catch { case e : IllegalArgumentException =>
16
+ println(" Correctly failed to retrieve illegal name, message: " + e.getMessage)
17
+ }
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments