Versions Compared

Key

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

...

Code Block
languagegroovy
void exec(@DelegatesTo.Target ex, @DelegatesTo Closure c) {
    c.delegate = ex
    c()
}

class Executor {
    void launchvoid launch() {}
}

def ex = new Executor()

exec(ex) {
    launch()
}

...

Code Block
languagegroovy
@NotNull
@Length(13)
@Pattern(/\d{12}(\d|X)/)
@groovy.transform.AnnotationCollector
@interface ISBN13@interface ISBN13 {}

@ISBN13 as a single annotation can now be applied on code elements, instead of applying the entire annotation gang::

...

Code Block
languagegroovy
@groovy.transform.AnnotationCollector([Service, Transactional])
@interface TransactionalService@interface TransactionalService {}

But we want to change the propagation strategy for the underlying @Transactional annotation, we do so by passing the parameter to the meta-annotation:

Code Block
languagegroovy
@TransactionalService(propagation = "mandatory")
class BankingServiceclass BankingService { }

Note that if two combined annotations share the same parameter name, the last annotation declared wins and gets the parameter passed to the meta-annotation.

...

Code Block
languagegroovy
import static java.lang.Math.*

assert sin(PI/2) == 1

For evaluating such math expressions, you wish to make the static import implicit, so that the final script will actually look like this:

Code Block
languagegroovy
assert sinassert sin(PI/2) == 1

If you’d run it as is, you’d get an error message saying:

...