-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Description
When type hierarchy is introduced: https://docs.scala-lang.org/scala3/book/first-look-at-types.html
it is said that
…it means that we cannot pattern match on values of type
Any, but only on values that are a subtype ofMatchable.
The type Matchable is used in the example here: https://docs.scala-lang.org/scala3/book/why-scala-3.html
def isTruthy(a: Matchable) = a match
case 0 | "" => false
case _ => trueBut here, the traditional Any is used: https://docs.scala-lang.org/scala3/book/taste-control-structures.html
def getClassAsString(x: Any): String = x match
case s: String => s"'$s' is a String"
case i: Int => "Int"
case d: Double => "Double"
case l: List[_] => "List"
case _ => "Unknown"Which is confusing.
Altair-Bueno
Metadata
Metadata
Assignees
Labels
No labels