It seems I can not use Closure as a parameter for the constructor of the superclass when it is specified in a string.
class Base {
def c
Base(c) {
this.c = c
}
void callMyClosure() {
c()
}
}
class Upper extends Base {
Upper() {
super( { println 'called' } )
}
}
u = new Upper()
u.callMyClosure()
Compilation failed with message Constructor call must be the first statement in a constructor..
I understand this is a somewhat strange use case, and so far I can create it around it. But it interests me, can this be expected? Or did I misunderstand the syntax?
source
share