Re: Why introduce the lazy keyword?
Todor Boev wrote:
> As the title says: why introduce another keyword when there already exists a lazy mechanism for the
> method parameters?
>
> def foo(lazy: => Int)
Because that is not lazy, that is by name:
scala> def f(byName: => Int) = { byName + byName }
f: (=> Int)Int
scala> f({println("Foo"); 2})
Foo
Foo
res20: Int = 4
scala> lazy val g = { println("Bar"); 2 }
Bar
g: Int = 2
scala> g + g
res21: Int = 4
- Florian