Scala学习系列-特质(trait)

(未完)

线性化

1
2
3
4
5
class Animal
trait Furry extends Animal
trait HasLegs extends Animal
trait FourLegged extends HasLegs
class Cat extends Animal with Furry with FourLegged

Notes

本文基于Scala2.12.13

参考

  1. https://docs.scala-lang.org/tour/traits.html
  2. https://docs.scala-lang.org/tour/self-types.html
  3. https://scala-lang.org/files/archive/spec/2.12/05-classes-and-objects.html#traits
  4. https://scala-lang.org/files/archive/spec/2.12/05-classes-and-objects.html#class-linearization