Take the following Scala code:
import scala.collection.mutable.HashMap
class father[T,K:Numeric] extends HashMap[T,K]
class sonA[T] extends father[T, Long]
class sonB[T] extends father[T, Double]
def func_sonA[T](x: List[T]) = {
// code
new sonA[T]
}
def func_sonB[T](x: List[T]) = {
// code
new sonB[T]
}
val strList = List("one", "two", "three", "four")
val intList = List(1,2,3,4)
val both:List[List[Any]] = List(strList, intList)
val mapped = both.map(x =>
x match {
case i:List[String] => func_sonA(i)
case i:List[Int] => func_sonB(i)
}
)
The type for mapped is: List[father[_ >: String with Int, _ >: Long with Double : AnyVal]].
What exactly does _>: means?
What's the idea behind String with Int and what is it good for?
Seems that it can grow indefinitely (String with Int with Double With Long with...).
How can I specify the type of mapped to be just List[father] or List[father[Any, Any]] without losing the type information?
I'm having a bit of a difficulty finding answers since search results for phrases _>: aren't very relevant.
EDIT:
To illustrate the actual problem its causing, I want to use a function with a List[father[Any, Any]] input but I can't pass mapped. I'm getting a type mismatch error.
Function:
def bar(x: List[father[Any, Any]]) = {
println(x)
}
bar(mapped)
Error:
Error:(52, 9) type mismatch;
found : List[father[_ >: String with Int, _ >: Long with Double <: AnyVal]]
required: List[father[Any,Any]]
bar(mapped)
^
>:means.