今天看了一个Scala写的项目,里面看到有一段这样的代码:
html
trait BaseController extends BSONImplicits with JSONImplicits with StrictLogging { this: Controller => ...... }
而后经过看Scala Language Specification,知道这个语法叫作SelfType的。this
这里面咱们能够看到BaseController是扩展的BSONImplicits,可是BSONImplicits的基础类并不是Controller,因此经过这个语法让Scala将这个trait认为是Conroller类。而且BaseController能够使用Controller类的全部方法和变量。spa
能够看出SelfType语法类至关于继承,而且更灵活些。scala
更多用途咱们能够参考http://docs.scala-lang.org/tutorials/tour/explicitly-typed-self-references.html。code