DevOps / Apache Groovy Interview questions
What is the difference between a closure and a Java lambda?
A Groovy closure is a full object with its own identity, delegation strategy, and ability to be reassigned or reconfigured at runtime, like changing its delegate, while a Java lambda is a simpler, more restricted implementation of a single functional interface with no equivalent delegation concept.
Closures can access and modify effectively any variable from their enclosing scope, including reassigning it, whereas Java lambdas can only reference effectively final local variables from their enclosing scope and cannot reassign them.
Closures also carry runtime-introspectable properties like maximumNumberOfParameters and can be curried or memoized directly as built-in closure methods, capabilities a plain Java lambda doesn't expose without extra library support.
More Related questions...