In the following code, I am getting a compilation error stating that I have a type mismatch on ‘x’:
val someRef: java.lang.Long = 42L
someRef match {
case x: Long => println("The answer: " + x)
case _ => println("Unknown")
}
How do I get Scala to auto-unbox someRef in the match statement?
The type system doesn’t know about boxing at this level. But it does know that if there is an
Any, a boxedLongis really (presumably) supposed to be just aLong(from theAnyValpart of the class inheritance tree). So: