• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Is Lambda implement as anonymous inner class

Ranch Hand
Posts: 1325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw in tutorial that lamda is internally implement interface like antonymous innerclass. is it true ?
Posts: 15784
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lambda expression becomes an instance of a functional interface. I suppose it could be considered an anonymous inner class but reading through the JLS (https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27), I don't see where it's explicitly called out as such. That would have to be something you'd deduce by following the syntax definition which starts with the definition of a LambdaBody. I tried following the link trail but it got too deep and I don't see any value in knowing whether or not it's implemented as an anonymous inner class, at least not from an application programmer's point of view. That's way too much detail that I'd rather have Java take care of for me so I don't have to care.
Posts: 69813
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't. If you search the folder containing .class files you find an anonymous class causes a .class file to be created, called something like MyApp$1.class. You won't find such a .class file if you use a λ. You get an instance/object and, as Junilu says, that is all you need to know.
    Bookmark Topic Watch Topic
  • New Topic