2015-09-27 32 views

回答

3

我没有你描述的行为:

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

+0

对不起,你说得对,问题是由线程安全引起的。 – tribbloid