Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26729
| From | Sven Köhler <remove-sven.koehler@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java 8 closures vs. anonymous inner classes |
| Date | 2013-12-04 22:27 +0200 |
| Message-ID | <bg9hi7Fq23U1@mid.dfncis.de> (permalink) |
| References | <l7nuiv$ajm$1@news.albasani.net> |
Am 04.12.2013 21:07, schrieb Sebastian:
> Someone made a passing comment in another thread to the effect that Java
> 8 lambdas ("closures") were nothing but syntactic sugar for (anonymous)
> inner classes. Here are a three differences:
>
> 1) lambdas can only instantiate "functional" (single abstract method)
> interfaces
so?
> 2) lambdas have different scoping rules ("this" means different things)
so?
> 3) lambdas perform better due to the use of the invokedynamic JVM
> instruction. Type representation, instance creation, and invocation
> strategy are decided at runtime. This offers optimization potentials,
> because evaluating a lambda expression need not create a new instance
> each time. There could be „shared lambdas“ through use of a constant
> static method in a constant pool, needing no new class and/or new object.
When I was digging through the byte code, invokedynamic was simply used
to invoke some fancy method that would basically encapsulate the
creation of the lambda object (which then is nothing more than an
instance of some class that implements the interface in question).
So obviously, all some magic happens here - but the magic is pretty much
limited to some a bunch of things that may likely speedup the creation
of lambda objects.
My point being: after creating the object representing the lambda
object, everything is as it was before, even the performance I guess.
I suspect, one could easily have achieved the speed up (if there is any)
by re-using instances of some inner class instead of using invokedynamic
plus some magic in the JVM.
> This is quite a bit more than what I'd call "syntactic sugar".
Certainly. And the implementation of it all is probably pretty ugly too!
Regards,
Sven
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java 8 closures vs. anonymous inner classes Sebastian <news@seyweiler.dyndns.org> - 2013-12-04 20:07 +0100
Re: Java 8 closures vs. anonymous inner classes Sven Köhler <remove-sven.koehler@gmail.com> - 2013-12-04 22:27 +0200
Re: Java 8 closures vs. anonymous inner classes Patrick Roemer <sangamon@netcologne.de> - 2013-12-05 00:38 +0100
Re: Java 8 closures vs. anonymous inner classes v_borchert@despammed.com (Volker Borchert) - 2013-12-04 23:45 +0000
Re: Java 8 closures vs. anonymous inner classes Roedy Green <see_website@mindprod.com.invalid> - 2013-12-06 13:28 -0800
Re: Java 8 closures vs. anonymous inner classes Arne Vajhøj <arne@vajhoej.dk> - 2013-12-14 16:46 -0500
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-14 03:13 -0400
Re: Java 8 closures vs. anonymous inner classes "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-12-14 12:03 +0000
Re: Java 8 closures vs. anonymous inner classes Arne Vajhøj <arne@vajhoej.dk> - 2013-12-14 17:02 -0500
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-15 14:33 -0400
Re: Java 8 closures vs. anonymous inner classes Arne Vajhøj <arne@vajhoej.dk> - 2013-12-14 17:00 -0500
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-15 15:05 -0400
Re: Java 8 closures vs. anonymous inner classes Wanja Gayk <brixomatic@yahoo.com> - 2013-12-17 20:09 +0100
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-20 22:28 -0400
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-21 11:54 +0000
Re: Java 8 closures vs. anonymous inner classes Joerg Meier <joergmmeier@arcor.de> - 2013-12-21 18:27 +0100
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-21 18:23 +0000
Re: Java 8 closures vs. anonymous inner classes Tim Slattery <tim@risingdove.com> - 2013-12-21 14:56 -0500
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-21 20:10 +0000
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-21 21:18 +0000
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-21 14:52 -0400
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-21 19:35 +0000
Re: Java 8 closures vs. anonymous inner classes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-12-21 19:34 -0400
Re: Java 8 closures vs. anonymous inner classes leif.roar@invalid.com (Leif Roar Moldskred) - 2013-12-22 05:02 -0600
Re: Java 8 closures vs. anonymous inner classes lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-12-22 11:12 +0000
Re: Java 8 closures vs. anonymous inner classes Wanja Gayk <brixomatic@yahoo.com> - 2013-12-22 21:24 +0100
csiph-web