Lambda behaving differently than anonymous inner class
Victor Antunes
victor.antunes.ignacio at gmail.com
Wed Mar 26 15:21:11 UTC 2014
Yes, using { return t++ } also reproduces the output 3. Forgot to mention
that, sorry.
Also, I've tested using both build build 1.8.0-b81 and build 1.8.0-b132
under Ubuntu 12.04, if that's of any interest.
2014-03-26 12:14 GMT-03:00 Sam Pullara <spullara at gmail.com>:
> I'm not sure there is a valid use case but it looks like a bug to me. Does
> it reproduce if you define the lambda as { return t++; } ?
>
> Sam
>
> ---
> Sent from Boxer | http://getboxer.com <http://bit.ly/1hRkK2W>
> On March 26, 2014 at 8:03:19 AM PDT, Victor Antunes <
> victor.antunes.ignacio at gmail.com> 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);}
>
> Supplier s1 = new Supplier() {
>
> @Override
> public Integer get(Integer t) {
> return t++;
> }};Supplier s2 = 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
>
>
--
att.
Victor Antunes
More information about the lambda-dev
mailing list