I'm trying to write a short snippet of scala code to understand parenthesesless method and postfixOps.
Here is my code:
import scala.language.postfixOps
object Parentheses {
def main(args: Array[String]) {
val person = new Person("Tom", 10);
val tomAge = person getAge
println(tomAge)
}
class Person(val name: String, val age: Int) {
def getAge = {
age
}
}
}
However, while compiling it, I have a problem says:
error: recursive value tomAge needs type
println(tomAge)
If I replace the method call person getAge
to person.getAge
, the program will run correctly.
so why the function call of person getAge
failed?