Any boilerplate which is rare in normal java code, but common when
working with a specific library is something we'd rather support by
way of a unique annotation that is put in a package that reflects its
design to work with that specific library. We don't have any yet, but,
at least I'm not opposed to such an idea (Roel is on vacation, so
can't ask him what he thinks. I recall we discussed this before and
agreed on this, though). However, this situation is different.
Let's have a closer look:
Form1Identifier is to get 2 constructors, both generated by lombok,
one of which is to take no arguments, and which is to call the no-args
super constructor. The other constructor is to take all fields in
Form1Identifier as parameters, *AND*, on top of that (and in front of
them), all constructors from the some-args constructor in the
superclass.
That sounds random to me. Remember that the superclass may have 20
constructors as far as we know. Why should AllArgsConstructor call
that specific constructor? Only because that constructor so happens to
have been generated by lombok with the same annotation, and an
inherit=true stuck onto that? We can't actually tell that happened,
lombok annotations are source retention only, and the constructors are
by design indistinguishable from a handwritten one.
So, should AllArgsConstructor take the some-args constructor because
its the constructor of the superclass with the most parameters on it,
and "AllArgsConstructor" more or less implies that it should go for
the most parameters? Maybe, with an error if there's more than 1
constructor with that number of parameters in the super? This feels
arbitrary to me, and that's bad: A programmer doesn't know which
constructor lombok has taken until he opens up the lombok
documentation, that's a failure of API design. We could let you
explicitly name the constructor you want, but now you're programming
in lombok-specific annotation DSL language, instead of in java. You
save only a handful of characters now, lombok isn't really delivering
a lot of value in such a situation.
In my opinion, forcing a programmer to create a large class hierarchy,
each class having multiple constructors is just disastrous. I know of
no API built around a complex hierarchy that's anything but a
clusterfail (example: swing!). These kinds of headaches start popping
up.
This problem should have been solved by making Identifier (which is
hopefully abstract!) an interface, and then all you really need to do
is put:
private Long id;
in every subclass, which is some boilerplate but manageable, and it
does greatly help clarity: Every class is responsible for its own id.
Because all these classes implement Identifier, you can use getId()
and setId() on any identifier instance. You've also removed a lot of
the class hierarchy: You've just got a bunch of XIdentifier classes,
which all have no superclass (well, java.lang.Object). They do all
implement the Identifier interface though, so you can generalize them.
Incidentally, as I've explained earlier in this thread, lombok needs
resolution to look at the constructors of parent classes, and it
currently doesn't, so we couldn't build this feature even if it didn't
have all these problems associated with it.
On Sep 15, 2:43 pm, Sven Linstaedt <
sven.linsta...@googlemail.com>