I start to learn scala by writing simple code.
I'm a little confused about the behavior of below code.
class BasicUsage {
private val incr = (x: Int) =>
{
println("incr invoked")
x + 1
}
private val add = (x: Int, y: Int) =>
{
println("add invoked")
if (x == 0 || y == 0) {
0
} else {
x + y
}
}
def testFuns(): Unit =
println(add(1,2))
println(incr(5))
}
When invoking testFuns(), the output is as below,
incr invoked
6
add invoked
3
Per my understanding, functions add() should be called firstly, then incr() should be invoked.
What's the mistake in above code? Do I misunderstand the usage of function and method?
Thanks very much,