...
| Code Block |
|---|
|
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 |
|---|
|
@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 |
|---|
|
@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 |
|---|
|
@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 |
|---|
|
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 |
|---|
|
assert sinassert sin(PI/2) == 1 |
If you’d run it as is, you’d get an error message saying:
...