Using scala 2.10
, in scala REPL. I have two definitions of myf
, which is overloaded using different argument type. But when I call myf
(line 7), it calls def myf(data:List[Int])
instead of def myf(data:List[String])
. Despite that the argument itself is of type dataString:List[String]
.
How do I call myf(data:List[String])
inside myf(data:List[Int])
?
I tried to handle type erasure with (implicit d: DummyImplicit)
as shown in here
def myf(data:List[String]) : Unit = {
data.foreach(println)
}
def myf(data:List[Int])(implicit d: DummyImplicit) : Unit = {
val dataString:List[String] = data.map(_ + 1000).map(_.toString) // do something else before toString
myf(dataString:List[String]) // want to call myf(data:List[String]), does not want to call myf(data:List[Int])
}
val d:List[Int] = List(1,2,3)
myf(d)
Errors to:
Name: Compile Error
Message: <console>:50: error: type mismatch;
found : List[String]
required: List[Int]
myf(dataString:List[String]) // want to call myf(data:List[String]), does not want to call myf(data:List[Int])