Why could we use traits compiled with 2.11 from 2.12?

假如想象 提交于 2019-12-10 11:40:03

问题


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?

来源:https://stackoverflow.com/questions/39139589/why-could-we-use-traits-compiled-with-2-11-from-2-12

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!