Is a a good idea to retrofit all foreach loop to use lambda ? Was: Checked exceptions within Block<T>

Michael Hixson michael.hixson at gmail.com
Sun Jan 13 01:22:08 PST 2013


Hi Remi,

When you say this, you're talking about the generic Iterable.forEach
that defaults to "for (foo bar : baz)" implementation, right?  You're
not talking about overridden implementations like ArrayList.forEach or
Stream.forEach (for the streams returned by the current library)?

-Michael

On Sat, Jan 12, 2013 at 11:04 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> On 01/12/2013 05:12 AM, Michael Hixson wrote:
>> An issue that came up repeatedly was that I wanted refactor code like this:
>>
>>    for (Value value : values) {
>>      ...
>>    }
>>
>> Into this:
>>
>>    values.forEach(value -> {
>>      ...
>>    });
>
> hijacking this thread...
>
> Blindly retrofitting all foreach loops to use lambda instead will cause
> you some perf trouble,
> because the VM JIT is currently not as good as optimizing lambda calls
> as it optimizes loops.
>
> If you have few elements (<10 000) you should not care because otherwise,
> it's better to keep the good old for each loop, at least for now.
>
> cheers,
> Rémi
>
>
>
>
>


More information about the lambda-dev mailing list