Why could we use traits compiled with 2.11 from 2.

2019-06-03 11:50发布

问题:

While understanding this answer I wrote my own example which uses a trait with scala-library version 2.11.4:

trait Trace {
  def id(): Int
  def concrete(i : Int) = println(i)
}

from a program uses version 2.12.0-M5.

object App {
  def main(args: Array[String]) = {
    println("st")
    val t = new TraceImpl
    println(t.id())
    t.concrete(10)
  }

  class TraceImpl extends Trace{
    override def id(): Int = 1
  }
}

I expected that some exception would be thrown at runtime, but the program works fine and prints:

st
1
10

Why? Runtime implementation of traits is supposed to be changed as of version 2.12.x?

标签: scala traits