Effectively final effective?
John Nilsson
john at milsson.nu
Sun Feb 28 07:15:25 PST 2010
On Sun, Feb 28, 2010 at 11:29 AM, Peter Levart <peter.levart at gmail.com>wrote:
> for(int i = 0; i < 3; i++) {
>
> final int ii = i;
>
> funs.add(()->ii);
>
> }
>
> or:
>
> for(int i = 0; i < 3; i++) {
>
> @SuppressWarnings("for loop index capture")
>
> funs.add(()->i);
>
> }
>
> Depending whether you want your program to print 012 or 333 (respectively).
>
> That's what I think is a good enough solution to this problem.
>
> Regards, Peter
>
Then someone comes along and "refactors" the code from
for(int i = 1; i <= 3; i++) //Can I get this right?
funs.add(()->i);
to
for(int i : in(1,2,3))
fins.add(()->i);
Accidentally breaking indexing semantics.
BR,
John
More information about the lambda-dev
mailing list