Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Lambda Expressions  RSS feed

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The higher order functions in Scala when compiled, is compiled to a class. This sometimes results in a class mess. How are lambda expressions compiled into? Do they also get compiled to a class definition? Was just curious to know!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are not compiled into anonymous inner classes - a lambda expression is not just syntactic sugar for anonymous inner classes.

They are compiled into compiler-generated methods that are added to the class they are in.

Brian Goetz, who led the Project Lambda project at Oracle in the past years, gave a talk on JavaOne, Devoxx and other conferences last year, in which he explained in detail how it all works behind the scenes, which different options they investigated etc.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds a lot better than the way the higher order functions are compiled in Scala.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper, is this also true for lambda's that are returned from methods, or are assigned to interface references?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!