Skip to main content
squid314's user avatar
squid314's user avatar
squid314's user avatar
squid314
  • Member for 11 years, 7 months
  • Last seen more than 7 years ago
comment
Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?
Java lambdas are not strictly closures. Nor are they anonymous inner classes. They do NOT carry a reference to all variables in scope where they are declared. They ONLY carry a reference to the variables they actually reference. This also applies to the this object which could be referenced. A lambda, therefore, does not leak resources simply by having scope for them; it only holds on to the objects it needs. On the other hand, an anonymous inner class can leak resources, but does not always do so. See this code for an example: a.blmq.us/2mmrL6v
awarded