File tree Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Original file line number Diff line number Diff line change
1
+ package scala
2
+
3
+ /** A base trait of all enum classes */
4
+ trait Enum extends Product , Serializable :
5
+
6
+ /** A number uniquely identifying a case of an enum */
7
+ def ordinal : Int
8
+ protected def $ordinal : Int
9
+
Original file line number Diff line number Diff line change 1
1
package scala
2
2
3
3
/** A base trait of all enum classes */
4
- trait Enum {
4
+ trait Enum :
5
5
6
6
/** A number uniquely identifying a case of an enum */
7
7
def ordinal : Int
8
8
protected def $ordinal : Int
9
- }
Original file line number Diff line number Diff line change 1
1
package scala
2
2
3
3
trait EnumValue extends Product , Serializable :
4
- override def canEqual (that : Any ) = true
4
+ override def canEqual (that : Any ) = this eq that. asInstanceOf [ AnyRef ]
5
5
override def productArity : Int = 0
6
6
override def productPrefix : String = toString
7
7
override def productElement (n : Int ): Any =
8
- throw IndexOutOfBoundsException (n.toString() )
8
+ throw IndexOutOfBoundsException (n.toString)
9
9
override def productElementName (n : Int ): String =
10
- throw IndexOutOfBoundsException (n.toString() )
10
+ throw IndexOutOfBoundsException (n.toString)
Original file line number Diff line number Diff line change @@ -2,11 +2,16 @@ abstract sealed class List[T] extends Enum
2
2
object List {
3
3
final class Cons [T ](x : T , xs : List [T ]) extends List [T ] {
4
4
def $ordinal = 0
5
+ def canEqual (that : Any ): Boolean = that.isInstanceOf [Cons [_]]
6
+ def productArity : Int = 2
7
+ def productElement (n : Int ): Any = n match
8
+ case 0 => x
9
+ case 1 => xs
5
10
}
6
11
object Cons {
7
12
def apply [T ](x : T , xs : List [T ]): List [T ] = new Cons (x, xs)
8
13
}
9
- final class Nil [T ]() extends List [T ] {
14
+ final class Nil [T ]() extends List [T ], EnumValue {
10
15
def $ordinal = 1
11
16
}
12
17
object Nil {
You can’t perform that action at this time.
0 commit comments