在Scala中,在类定义之后的第一行,lambda表达式的语法是什么样的?

16 浏览
0 Comments

在Scala中,在类定义之后的第一行,lambda表达式的语法是什么样的?

在下面的代码中,a=>的含义是什么?它像this一样指向实例化对象的指针吗?

class A {
  a=>
  def methodB()={
     .....
  }
}

0
0 Comments

在Scala中,类定义之后的第一行中的lambda定义被称为self reference或self type。在这种情况下,它的意思是“创建一个名为'a'的符号,并将其指向this引用”。

为了更多了解self reference的概念和用法,可以参考SO Scala教程中的"Self references"(第17章)部分。以下是一些相关链接:

- [Unify types](https://stackoverflow.com/questions/932701)

- [Self reference naming](https://stackoverflow.com/questions/4017357)

- [Multiple self references](https://stackoverflow.com/questions/4355060)

- [Difference between self references and subtyping](https://stackoverflow.com/questions/1990948)

以上是关于Scala中类定义后的第一行lambda定义的self reference的概念以及相关解决方法的信息。

0