groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk Cronjé <>
Subject Additional code to be called from TupleConstructor
Date Wed, 06 Jan 2016 21:55:11 GMT
The following has come up for me in a number of cases. I don't think 
there is any support for it today in Groovy (correct me if I'm wrong, 
please), but I think it could be a useful addition.

I like to do some additional intialisation work once the properties have 
been populated,

    class Example {
       String foo
       String bar

       Example( Map props = [:] ) {
         // Do some work here to initialise properties from the supplied map

         // Do some other initialisation work, possibly calling a method
    in order to
         // initialise private field 'something'

       private def something

I am a big fan of @TupleConstructor, but it will not work for the above 
case. Here, I am thinking that if one could do something like

    @TupleConstructor( init=myInitMethod )
    class Example {
       String foo
       String bar

       private void myInitMethod() {
         // Do more init work in here

it would be quite useful. I don't know what the limitations are in order 
to implement somethin like this. It's a thought at present...

Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r

View raw message