How are Scala traits compiled into Java bytecode?

前端 未结 4 2034
半阙折子戏
半阙折子戏 2020-11-30 00:33

I have played around with Scala for a while now, and I know that traits can act as the Scala equivalent of both interfaces and abstract classes. How exactly are traits comp

4条回答
  •  执念已碎
    2020-11-30 00:51

    A very good explanation of this is in:

    The busy Java developer's guide to Scala: Of traits and behaviors - Traits in the JVM

    Quote:

    In this case, it [the compiler] drops the method implementations and field declarations defined in the trait into the class that implements the trait

提交回复
热议问题