“outer =>”是什么意思?真的吗?
有没有关于“outer =>”的文档特征?它看起来像是带有推断类型的自类型注释。但我有一种感觉,我错了。
如果是这种情况,是否只是表达对 super 的访问的不同方式?
trait A extends (B => C) {
outer =>
def apply(x: B): C = outer(x)
}
Is there any documentation on the "outer =>" feature? It looks like a self type annotation with an infered type. However I have the feeling that I am wrong.
If it would be the case, is it only a different way to express access to super
?
trait A extends (B => C) {
outer =>
def apply(x: B): C = outer(x)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是
super
,而是外部范围。这是一种给不同作用域起别名的方法。例如:这里有一个更好的说明。
(*) 还有另一种方法可以达到相同的效果,但这超出了这个问题。
Not
super
, but the outer scope. It's a way to aliasing different scopes. For example:There is a better illustration here.
(*) There exist another way to have the same effect, but it's beyond this question.
这是访问
this
的不同方式。当外部this
被内部类中的另一个this
遮蔽时,它非常有用。这样,您只需为外部this
指定一个附加名称(原始this
在作用域内时仍然可用,因此不是重命名)。It is a different way to access
this
. It is useful in cases where an outerthis
would be shadowed by anotherthis
in an inner class. That way, you can just give the outerthis
an additional (the originalthis
would still be available when it is in scope so it’s not a renaming) name.