特牛网址导航

scala学习笔记 - 高级类型(二)_logged exception-CSDN博客

网友收藏
文章浏览阅读114次。自身类型特质可以要求混入它的类扩展自另一个类型,用自身类型(self type)的声明来定义特质:this: 类型 =>这样的特质只能被混入给定类型的子类当中。在如下示例中,LoggedException特质只能被混人扩展自 Expcetion的类:trait Logged { def log(msg: String) }trait LoggedException extends Logged{ this: Exception => def log(){ lo_logged exception
标签:logged exception