groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: @TupleConstructor: what am I doing wrong?
Date Thu, 11 Jan 2018 22:52:16 GMT
I haven't checked the code yet but I think @Builder and @ToString
originally had similar issues and we added an `allProperties` attribute
with default true. Perhaps that is needed here too. I'll try to check the
code shortly.

On Thu, Jan 11, 2018 at 11:57 PM, Mauro Molinari <mauromol@tiscali.it>
wrote:

> Hello all,
> I'm getting crazy because I can't understand what I'm doing wrong.
>
> Consider this (it can be pasted on the Groovy console):
>
> import groovy.transform.TupleConstructor
>
> public class Foobar {
>   private Long id;
>
>   public Long getId() { return this.id; }
>   public void setId(Long id) { this.id = id; }
> }
>
> @TupleConstructor(includeSuperProperties=true)
> class Ext extends Foobar {
>   String foo
> }
>
> Ext.constructors.each {
>     println it
> }
> println 'end'
>
> The result is just:
>
> public Ext(java.lang.String)
> public Ext()
> end
>
> But isn't id a property (as per the Java beans conventions)???
>
> If I replace includeSuperProperties=true with includeSuperFields=true, I
> get the expected result:
>
> public Ext()
> public Ext(java.lang.Long)
> public Ext(java.lang.Long,java.lang.String)
> end
>
> But in more complex cases, includeSuperFields=true will include unwanted
> fields that are not actually properties.
>
> What am I doing wrong?
>
> Thanks in advance,
> Mauro
>

Mime
View raw message