Hello,
I'm currently struggeling on how to comfortably define @EqualsAndHashCode for a subclass that inherits its id attribute from its superclass:
Example:
@EqualsAndHashCode(of = "id", callSuper = false)
public class Site {
private Integer id;
}
@EqualsAndHashCode(exclude = { "name" }, callSuper = true)
public class SubSite extends Site {
private String name;
}
The superclass "Site" has an attribute that identifies it, namely "id". The subclass "SubSite" doesn't have any identifying attribute, but it ihnerits it from its superclass.
How can I now define the @EqualsAndHashCode annotation in the subclass in a comfortable way?
I tried the following out:
1. @EqualsAndHashCode(of = "id", callSuper = true)
-> This gives me a compiler warning in Eclipse ("This field does not exist, or would have been excluded anyway."), which I want to avoid. It is the same warning as I would write of = "dummy" or so.
2. @EqualsAndHashCode(exclude = { "name" }, callSuper = true)
-> This is dangerous when the next developer adds an additional attribute, e.g. "street", and forgets to adapt the exclude list.
3. add a dummy attribute to the subclass, and all other subclasses, which are many
-> No professional solution
Does anyone have another idea or is there missing a feature in Lombok?
I would wish to be able to define also super class attributes in the of-statemant in the case where callSuper is equals to true. Would this be a solution for future Lombok versions?
Ciao, Michael