Lambda behaving differently than anonymous inner class
Remi Forax
forax at univ-mlv.fr
Wed Mar 26 18:40:37 UTC 2014
On 03/26/2014 06:50 PM, Sam Pullara wrote:
> I think there was some discussion about whether the lambda parameters
> should be final. I still think they should have been.
>
> Sam
Yes, but method parameters should have been final by default too.
IDE should mark every parameters final by default.
>
> ---
> Sent from Boxer | http://getboxer.com <http://bit.ly/1hRkK2W>
and stop sending email from boxer, there is still no Android version :)
Rémi
> On March 26, 2014 at 10:48:18 AM PDT, Remi Forax <forax at univ-mlv.fr>
> wrote:
>> On 03/26/2014 05:56 PM, Dan Smith wrote:
>> > Thanks for the report. The bug is filed here:
>> >
>> > https://bugs.openjdk.java.net/browse/JDK-8038420
>> >
>> > —Dan
>>
>> Yes, definitively a bug !
>>
>> Victor, modify a parameter inside a lambda is something weird|.||
>> Suppliers2 =t ->t++;|
>> means
>> | Suppliers2 =t ->{
>> t = t + 1;
>> return t;
>> };
>> |so this is equivalent to|
>> Suppliers2 =t ->t+ 1;|
>>
>> cheers,
>> Rémi
>>
>> >
>> > On Mar 26, 2014, at 9:03 AM, Victor Antunes wrote:
>> >
>> >> Hello all,
>> >>
>> >> This e-mail is a follow-up to a question I've posted on StackOverflow:
>> >>
>> http://stackoverflow.com/questions/22648079/lambda-behaving-differently-than-anonymous-inner-class
>> >>
>> >>
>> >> I'm relatively new to Java, and decided to pick up on lambda since
>> the past
>> >> few days. So I wrote a very simple anonymous inner class and wrote an
>> >> equivalent lambda.
>> >>
>> >> However, the lambda output was different, and it very strongly
>> appears to
>> >> be a bug.
>> >>
>> >> Given:
>> >>
>> >> interface Supplier{
>> >>
>> >> T get(T t);}
>> >>
>> >> Suppliers1 = new Supplier() {
>> >> @Override
>> >> public Integer get(Integer t) {
>> >> return t++;
>> >> }};Suppliers2 = t ->
>> >> t++;System.out.println(s1.get(2));System.out.println(s2.get(2));
>> >>
>> >> The output is 2 and 3, NOT 2 and 2, as one would expect.
>> >>
>> >> More info, including discussion about bytecode is available at the
>> SO link
>> >> above.
>> >>
>> >> I'm also new to this list, so apologies if I've broken any mailing
>> list
>> >> etiquette.
>> >>
>> >> --
>> >> Kind regards,
>> >>
>> >> Victor Antunes
>> >>
>> >
>>
>>
More information about the lambda-dev
mailing list