本文介绍了"outer =>" 是什么意思?实际意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有关于外部 =>"功能的文档?它看起来像一个带有推断类型的自类型注释.但是我觉得我错了.

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.

如果是这样,是否只是一种表达对super的访问的不同方式?

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)
}

推荐答案

不是super,而是外部作用域.这是一种别名不同范围的方法.例如:

Not super, but the outer scope. It's a way to aliasing different scopes. For example:

class A(val x:Int) { thisA =>
 class B {
   val x = 2
   val y = x + thisA.x // without thisA how could we use A.x instead of B.x ? (*)
 }
}

这里有一个更好的说明.

(*) 有另一种方法可以产生相同的效果,但这超出了这个问题.

(*) There exist another way to have the same effect, but it's beyond this question.

这篇关于"outer =>" 是什么意思?实际意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 12:48
查看更多