0

Scala覆盖的字段:虚拟表中也有覆盖的字段吗?

我是 Scala 的新手。从概念上讲,被覆盖的类方法在虚拟表中,但我不确定被覆盖的字段是否也在虚拟表中?

   class A
   {
        private var str: String = "A"
        val x: A = this

        override def toString(): String = str

        def m1(other: AnyRef): AnyRef = {
          println("This is A.m1(AnyRef)")
          other
        }
    }

    class B extends A {
        private var str: String = "B"
        var z: Int = 0
        override val x: B = this

        override def m1(other: AnyRef): B = {
          println("This is B.m1(AnyRef)")
          this
        }
    }

对于上面的代码片段,我的理解是方法分别m1class AB的虚拟表中,但我不确定字段x是否也在虚拟表中。

4

0 回答 0