I'm trying to understand the differences between these 2 syntaxes in scala and why they have not the same result.
testVal
and
testVal2
are not defined in the same way
object FunctionVsVal2 extends App {
val testVal: () => Int = {
val r = util.Random.nextInt
() => r
}
val testVal2: () => Int = () => {
val r = util.Random.nextInt
r
}
println(testVal())
println(testVal())
println(testVal2())
println(testVal2())
}
Thanks