2
我在玩Scala时发现下面的代码不能编译,为什么?Simple Scala Mind Bender with Closures/Higher Order函数/方法
case class A(a:Int) {
def getA:()=>Int =() => a
def getAA()=a
def getAAA=a
}
object Test extends App{
val a =A(3)
def printInt(f:()=>Int)=println(f())
printInt(a.getA) // fine, prints 3
printInt(a.getAA) // fine, prints 3
printInt(a.getAAA) // this does not compile, why ?
}
是什么a.getA,a.getAA和a.getAAA之间的区别?