Content deleted Content added
m Open access bot: url-access updated in citation with #oabot. |
BrainStack (talk | contribs) Link suggestions feature: 2 links added. |
||
Line 116:
</syntaxhighlight>
In the above, the variable {{mono|a}} initially refers to a lazy [[integer]] object created by the lambda expression <code>() -> 1</code>. Evaluating this lambda expression is similar{{efn|name=Java Lambda|Java lambda expressions are not exactly equivalent to anonymous classes, see [[Anonymous function#Differences compared to Anonymous Classes]]}} to constructing a new instance of an [[anonymous class]] that implements <code>Lazy<Integer></code> with an {{mono|eval}} method returning {{mono|1}}.
Each iteration of the loop links {{mono|a}} to a new object created by evaluating the lambda expression inside the loop. Each of these objects holds a reference to another lazy object, {{mono|b}}, and has an {{mono|eval}} method that calls <code>b.eval()</code> twice and returns the sum. The variable {{mono|b}} is needed here to meet Java's requirement that variables referenced from within a lambda expression be effectively final.
Line 217:
0
</syntaxhighlight>
:The above example shows that lists are evaluated when called, but in case of [[iterator]], the first element '0' is printed when need arises.
====.NET ====
|