You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Schalk Cronjé <ys...@gmail.com> on 2016/01/06 22:55:11 UTC
Additional code to be called from TupleConstructor
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
Re: Restarting GroovyLab development
Posted by Paul King <pa...@asert.com.au>.
Good news Stergios. Keep up the good work!
Cheers, Paul.
On Fri, Jan 8, 2016 at 3:54 AM, sterg <st...@teiemt.gr> wrote:
> Hi all,
>
> I like to to announce that I restarted to work on GroovyLab,
> with now a Github setting:
>
> https://github.com/sterglee/jlabgroovy
>
>
> I will be very happy for any collaborators!!
>
>
> Happy new year!!
>
> Stergios
Restarting GroovyLab development
Posted by sterg <st...@teiemt.gr>.
Hi all,
I like to to announce that I restarted to work on GroovyLab,
with now a Github setting:
https://github.com/sterglee/jlabgroovy
I will be very happy for any collaborators!!
Happy new year!!
Stergios
Re: Additional code to be called from TupleConstructor
Posted by Paul King <pa...@asert.com.au>.
Would something like the "pre" and "post" annotation params from
MapConstructor work for you?
Cheers, Paul.
On Thu, Jan 7, 2016 at 7:55 AM, Schalk Cronjé <ys...@gmail.com> wrote:
> 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
Re: Additional code to be called from TupleConstructor
Posted by Schalk Cronjé <ys...@gmail.com>.
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é <ys...@gmail.com> 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
Re: Additional code to be called from TupleConstructor
Posted by Paul King <pa...@asert.com.au>.
It's a new annotation for 2.5, so you'll need to look in the snapshot docs/zips.
On Thu, Jan 7, 2016 at 9:12 AM, Schalk Cronjé <ys...@gmail.com> 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
Re: Additional code to be called from TupleConstructor
Posted by Schalk Cronjé <ys...@gmail.com>.
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
Re: Additional code to be called from TupleConstructor
Posted by Alexander Klein <in...@aklein.org>.
Hi Schalk,
I like the idea, but as a small modification why not do something like:
@TupleConstructor( init={ myInitMethod() } )
class Example {
String foo
String bar
private void myInitMethod() {
// Do more init work in here
}
}
This way you could put all the initialization stuff into the closure
only if you like to - and for small actions this might be more compact.
What do you think?
Sascha
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