看来我可以用self
or this
用于引用混合实例或者更确切地说约束混合实例。例如,这些是等价的吗?
scala> trait A { self: List[_] => }
defined trait A
scala> trait B { this: List[_] => }
defined trait B
这只是一个约定,还是使用了与this
提供一些好处?
当您拥有引用封闭实例的成员类型时,使用“this”以外的名称可能会很有用。例如,
trait Outer { self =>
trait Inner {
def outer = self
}
}
更可取的是,
trait Outer {
trait Inner {
def outer = Outer.this
}
}
在某些情况下。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)