On 06/01/2016 23:41, Paul King wrote:
It's a new annotation for 2.5, so you'll need to look in the snapshot docs/zips.
That looks like what I want. I mostly use @TupleConstructor to get the map constuctor, so it looks like I could just use @MapConstructor in future.
On Thu, Jan 7, 2016 at 9:12 AM, Schalk Cronjé <[email protected]> wrote:On 06/01/2016 22:44, Alexander Klein wrote: @TupleConstructor( init={ myInitMethod() } ) class Example { I like that idea. On 06/01/2016 22:46, Paul King wrote: Would something like the "pre" and "post" annotation params from MapConstructor work for you? Paul, I tried to look for MapConstructor in the 2.4.5 docs, but could not find anything. Is it an annotation? Am 06.01.2016 um 22:55 schrieb Schalk Cronjé: 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 -- Schalk W. Cronjé Twitter / Ello / Toeter : @ysb33r
-- Schalk W. Cronjé Twitter / Ello / Toeter : @ysb33r
