extending a class - constructor issue

2,758 views
Skip to first unread message

jilt3d

unread,
Jan 10, 2011, 10:13:33 AM1/10/11
to Project Lombok
Hi,

I am using lombok 0.9.3 and found an interesting issue regarding
generated constructor using @Data when I extend another class. Here is
the example:

@Data
public class X {
protected final String x1;
protected final String x2;
}

@Data
public final class Y extends X {
private final String y1;
}

In Eclipse Outline View I see only one constructor generated by
lombok: Y(String). I am expecting to see something like Y(String,
String, String).
Additionally, I get a compile error: "Implicit super constructor X()
is undefined. Must explicitly invoke another constructor". I don't
want to have no-arg constructor anyway. By documentation, @Data
doesn't create such no-arg constructor. The compile error seems
unusual.
I tried with @AllArgsConstructor and individuals @Getters - the same
result.

Am I missing something?

Thanks! Keep that project alive, I find it very useful!

Reinier Zwitserloot

unread,
Jan 11, 2011, 9:02:47 AM1/11/11
to project-lombok
Yes, you're missing something.

@Data (and the bits it consists of) don't look at other classes. They don't know about your superclass's non-zero-arg constructor. This won't be changing anytime soon.

 --Reinier Zwitserloot



--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

Lord.Quackstar

unread,
Jan 11, 2011, 8:35:15 PM1/11/11
to project...@googlegroups.com
Any particular reason why? Is it difficult? Is there too much to do right now?

-Leon


From: Reinier Zwitserloot <rein...@gmail.com>
To: project-lombok <project...@googlegroups.com>
Sent: Tue, January 11, 2011 9:02:47 AM
Subject: Re: [project lombok] extending a class - constructor issue

rjee

unread,
Jan 14, 2011, 8:24:28 AM1/14/11
to Project Lombok


Yes, a very particular reason ;). To generate a constructor for a
super class one needs to know the types of the parameters. This
information is only available after java has performed resolution and
lombok is run in a pre-resolution step.

This doesn't apply for generating a constructor with the field of a
class. We can assume that the Argument types can go un-changed into
getters/setters and constructors as it is not possible to have two
different type of say a 'List' with one class.

Getting resolution information for lombok is not a trivial issue.
We've done a partial form of resolution for our new 'val' feature but
that was followed with a lot of pain. Obviously, we'd really like this
to work, but we don' t think this is going to happen in the near
future.

--
Robbert Jan Grootjans


On Jan 12, 2:35 am, "Lord.Quackstar" <lord.quacks...@gmail.com> wrote:
> Any particular reason why? Is it difficult? Is there too much to do right now?
>
> -Leon
>
> ________________________________
> From: Reinier Zwitserloot <reini...@gmail.com>
> To: project-lombok <project...@googlegroups.com>
> Sent: Tue, January 11, 2011 9:02:47 AM
> Subject: Re: [project lombok] extending a class - constructor issue
>
> Yes, you're missing something.
>
> @Data (and the bits it consists of) don't look at other classes. They don't know
> about your superclass's non-zero-arg constructor. This won't be changing anytime
> soon.
>
>  --Reinier Zwitserloot
>
> >Groups group forhttp://projectlombok.org/
>
> >To post to this group, send email to project...@googlegroups.com
> >To unsubscribe from this group, send email to
> >project-lombo...@googlegroups.com
> >For more options, visit this group at
> >http://groups.google.com/group/project-lombok?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups group forhttp://projectlombok.org/
Reply all
Reply to author
Forward
0 new messages