Why introduce the lazy keyword?
Hello everyone,
I am likely a future Scala fan - e.g. a current newby. I have been watching Scala for maybe 2 years
now and finally I'm taking the plunge and doing some serious exploration of the language. So...
As the title says: why introduce another keyword when there already exists a lazy mechanism for the
method parameters?
def foo(lazy: => Int)
Why not use the same mechanism for the lazy values?
class Foo {
val lazy: => Int = {println ("evaluating the answer"); 42}
}
This might be more verbose and than using a "lazy" in front but to me it seems more "regular". Maybe
there is some fundamental difference between the "by name" parameters and the lazy vals that I am
missing?
Respectfully,
Todor