I'm learning Scala and the following simple program got me stuck:
class ObjectPrinter[T <: AnyVal](x: T) {
def print(t: T) = { // <--- error here
case Is(i) => println("Integer: " + i)
case Ds(d) => println("Double: " + d)
case _ => println("Default")
}
case class Is(i : Int) extends ObjectPrinter[Int](i);
case class Ds(d: Double) extends ObjectPrinter[Double](d);
}
The error message is the following:
Missing type parameter for expanded function. The argument type of an anonymous function must be fully known. Expected type was: ?
The message is completely unclear to me. What do they mean, missing type parameter? I thought the type parameter follows after the case
, like Is(i)
. What function is expanded?
UPD: I want to return a function depending on the type of the argument passed in as a parameter.
def print(t: T) = t match { ... }
? Currently your method returns an anonymous function, andt
is not used. – Victor Moroz