1

I got into a long discussion on Reddit about whether or not Java lambdas are just sugar for anonymous classes. I contend that lambdas are different from anonymous classes in too many important respects to consider them just sugar for anonymous classes. But, some of the replies have me questioning this.

Can anyone, once and for all, list the exact technical differences between AIC and lambdas in Java? Is it true that once the code is hot and running it's really just an AIC? I thought no originally. AIC creates a new class that must be loaded for each unique use. Not so with lambdas right? Or do lambdas create new classes for each unique use?

Update: I'm especially curious what the actual implementation in various flavors of Java 8 are. I keep reading conflicting things.

8
  • 1
    I don't think this is a dup. The other question is more general. I'm looking for the real technical differences between the two. Commented Jul 18, 2017 at 14:43
  • As for your specific question "Not so with lambdas right?", consult the language spec: "These rules are meant to offer flexibility to implementations of the Java programming language, in that:... A new object need not be allocated on every evaluation.". Commented Jul 18, 2017 at 14:51
  • But what does Java 8 do now? I thought I knew but am getting conflicting answers. Commented Jul 18, 2017 at 14:53
  • 1
    Which implementation of Java 8? The point in that quote is that the implementor can do it in different ways. Commented Jul 18, 2017 at 14:53
  • 1
    If you're interested, I've watched this talk a few times which talks about some of the implementation details of java.lang.invoke (presumably on HotSpot): youtube.com/watch?v=lhGPndh8R3g which is a part of the lambda implementation. Commented Jul 18, 2017 at 15:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.