Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28890

Re: are lambdas a way to bring functional programming to java?

From Sebastian <news@seyweiler.dyndns.org>
Newsgroups comp.lang.java.programmer
Subject Re: are lambdas a way to bring functional programming to java?
Date 2014-07-01 21:52 +0200
Organization albasani.net
Message-ID <lov3h3$thm$1@news.albasani.net> (permalink)
References <ead6a498-272d-4ddd-b509-031bb858e882@googlegroups.com> <hpbujmlvfktw$.gwo2lpti2hsy.dlg@40tude.net> <ch13r992v98u5tqu88i2banltkpsgvhjkr@4ax.com> <MPG.2e1d0dba27ee4d221@202.177.16.121> <MPG.2e1d2056334506bc22@202.177.16.121>

Show all headers | View raw


Am 01.07.2014 20:46, schrieb Wanja Gayk:
> In article <MPG.2e1d0dba27ee4d221@202.177.16.121>, Wanja Gayk
> (brixomatic@yahoo.com) says...
>
> [..]
>>> Would it be a reasonable thing to say that a lambda is just a terser
>>> way to implement an instance of a one-use anonymous class that has a
>>> single method?
>>
>> Not quite, even though it looks a lot like it was.
> [..]
>> http://medianetwork.oracle.com/video/player/2623576348001
>> I found it pretty interesting.
>
> Sorry, that rather focussed on today's Lambda performance.
> This one gives a better overview over the differences to anonymous
> classes:
> http://medianetwork.oracle.com/video/player/1785479333001
>
> Kind regards,
> Wanja
>

Thanks for the pointer. It appears one way that lambdas differ from 
inner classes is that you are actively discouraged from thinking of 
lambdas as instances of classes (objects). In particular, lambdas seem 
to have no well-defined identity, which is to say among other things one 
cannot meaningfully compare them with equals.

Here‘s a source for this claim: Stuart Marks answer at
http://stackoverflow.com/questions/15221659/java-8-lambda-expression-and-first-class-values
from which I quote:

<quote>
Given that lambdas are converted into objects, they inherit (literally) 
all the characteristics of objects. In particular, objects:

- have various methods like equals, getClass, hashCode, notify, 
toString, and wait
- have an identity hash code
- can be locked by a synchronized block
- can be compared using the == and != and instanceof operators

and so forth. In fact, all of these are irrelevant to the intended usage 
of lambdas. Their behavior is essentially undefined. You can write a 
program that uses any of these, and you will get some result, but the 
result may differ from release to release (or even run to run!).
</quote>

You might also want to see the page „Are lambda expressions objects?“ 
from the Lambda FAQ at
http://www.lambdafaq.org/are-lambda-expressions-objects/

As Brian Goetz has memorably put it (on lambda-dev): 
"Lambdas-are-functions opens doors. Lambdas-are-objects closes them."

So, as far as the intention behind lambdas goes, and also with respect 
to semantics and some technical differences (byte-code, optimization 
potential), it is not reasonable to say that "a lambda is just a terser
way to implement an instance of a one-use anonymous class" - except as a 
first approximation that will serve you well in many circumstances.

-- Sebastian

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

are lambdas a way to bring functional programming to java? gdotone@gmail.com - 2014-06-27 16:50 -0700
  Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-06-27 20:14 -0400
    Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-06-27 20:23 -0400
      Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-06-28 14:43 +0200
        Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-01 14:34 -0700
          Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-07-01 22:01 -0400
          Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-02 20:52 +0200
            Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-02 13:08 -0700
              Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-03 03:13 +0200
              Re: are lambdas a way to bring functional programming to java? Joerg Meier <joergmmeier@arcor.de> - 2014-07-06 14:42 +0200
        Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-07-01 22:27 -0400
          Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-07-01 22:32 -0400
            Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-01 19:58 -0700
            Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-02 22:55 +0200
              Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-02 15:32 -0700
                Re: are lambdas a way to bring functional programming to java? Gene Wirchenko <genew@telus.net> - 2014-07-03 09:45 -0700
          Re: are lambdas a way to bring functional programming to java? leif.roar@invalid.com (Leif Roar Moldskred) - 2014-07-01 23:48 -0500
            Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-02 22:55 +0200
              Re: are lambdas a way to bring functional programming to java? Gene Wirchenko <genew@telus.net> - 2014-07-03 09:49 -0700
                Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-03 10:25 -0700
                Re: are lambdas a way to bring functional programming to java? Gene Wirchenko <genew@telus.net> - 2014-07-04 11:03 -0700
          Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-02 21:23 +0200
      Re: are lambdas a way to bring functional programming to java? Roedy Green <see_website@mindprod.com.invalid> - 2014-06-30 09:08 -0700
        Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-07-01 21:56 -0400
  Re: are lambdas a way to bring functional programming to java? Joerg Meier <joergmmeier@arcor.de> - 2014-06-28 12:11 +0200
    Re: are lambdas a way to bring functional programming to java? Roedy Green <see_website@mindprod.com.invalid> - 2014-06-30 08:50 -0700
      Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-06-30 09:09 -0700
      Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-01 19:27 +0200
        Re: are lambdas a way to bring functional programming to java? Wanja Gayk <brixomatic@yahoo.com> - 2014-07-01 20:46 +0200
          Re: are lambdas a way to bring functional programming to java? Sebastian <news@seyweiler.dyndns.org> - 2014-07-01 21:52 +0200
            Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-01 14:11 -0700
              Re: are lambdas a way to bring functional programming to java? Jan Burse <janburse@fastmail.fm> - 2014-07-22 14:37 +0200
                Re: are lambdas a way to bring functional programming to java? markspace <markspace@nospam.nospam> - 2014-07-22 10:39 -0700
                Sidetrack on generics (WAS: Re: are lambdas a way to bring functional programming to java?) Daniele Futtorovic <da.futt.news@laposte.net> - 2014-07-22 20:48 +0200
                Re: Sidetrack on generics (WAS: Re: are lambdas a way to bring functional   programming to java?) Chris Riesbeck <Chris.Riesbeck@gmail.com> - 2014-07-23 12:01 -0500
      Re: are lambdas a way to bring functional programming to java? Arne Vajhøj <arne@vajhoej.dk> - 2014-07-01 21:50 -0400
  Re: are lambdas a way to bring functional programming to java? Roedy Green <see_website@mindprod.com.invalid> - 2014-07-22 04:40 -0700
  Re: are lambdas a way to bring functional programming to java? Roedy Green <see_website@mindprod.com.invalid> - 2014-07-28 09:45 -0700

csiph-web