If you look at the API documentation for AnyRef
you will note that it does not provide an apply
method - so the error makes sense.
You can see the same behavior if you change your example to add a method to Y
that is not available on X
:
class X {
def f = println("X")
}
class Y extends X {
override def f = println("Y")
def f2 = println("Not in X")
}
val a : X = new Y
scala> a.f2
<console>:11: error: value f2 is not a member of X
a.f2
^