Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

That way, Groovy closure coercion to SAM types is as concise as Java 8 lambda closure convertion.conversion.

Here's another example using abstract classes, which are not supported by Java 8 lambda conversion:

Code Block
languagegroovy
abstract class SurroundedMessage {
    abstract String message()
    
    String surrounded() {
        "<< ${message()} >>"
    }
}
SurroundedMessage m = { 'hello' }
assert m.surrounded() == '<< hello >>'

 

@Memoized AST transformation for methods

...