I have a below class which uses covariance annotation and another type parameter for its method to which class type parameter is lower bound
class MyQueue[+T]{
def add[U >: T](arg:U):Unit= {
println("Arg value :"+ arg)
}
}
Given above code, I don't understand why below lines execute successfully. As per my understanding of lower bounds, method "add" should only accept value of type Int or its super-type.
val q1:MyQueue[Int] = new MyQueue[Int]
q1.add("string")
However, it gives expected compilation error (String do not conform to method add's type parameter bounds) if we explicitly specify the type argument as below
q1.add[String]("string")