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

Reply via email to