It is important to remember that Anythis is a super type of any type, i.e.
Any >: A
In particular, suppose that
val t = new Test[Int]
That A Int. Now we call
t.test("foo")
"foo" String, Any , , , test[B >: A](b : B) b, "foo" b Any.
,
class Test[+A](a : A) {
def test[B >: A](b : B) : (A,B) = (a,b)
}
,
val t = new Test(3)
val x = t.test("foo")
x: (Int, Any) = (3,foo)
, , Scala Any, A b. , Any Int String (. http://www.scala-lang.org/old/node/128), - , ,
val s = new Test(Nil)
val y = s.test("foo")
val z = s.test(List(1))
y: (scala.collection.immutable.Nil.type, java.io.Serializable) = (List(),foo)
z: (scala.collection.immutable.Nil.type, List[Int]) = (List(),List(1))
, A
scala> val a = new Test(new AnyRef())
a: Test[java.lang.Object] = Test@6771a12
scala> a.test("foo")
res6: (java.lang.Object, java.lang.Object) = (java.lang.Object@78b99f12,foo)
, , ? , "" "" , , ., , http://docs.scala-lang.org/tutorials/tour/lower-type-bounds.html , () A , " " A. ( , , , , , , , )