我沒有你描述的行爲:
C:\...>scala
Welcome to Scala version 2.11.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A {
def method(): Unit = println("A.method")
}
class B extends A {
def sup(): Unit = super.method()
override def method(): Unit = println("B.method")
}
class C extends B
// Exiting paste mode, now interpreting.
defined class A
defined class B
defined class C
scala> val c = new C
c: C = [email protected]
scala> c.sup()
A.method
正如你所看到的,c.sup()
電話A.method
,不B.method
。
對不起,你說得對,問題是由線程安全引起的。 – tribbloid