-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@EqualAndHashCode problems with subclasses #1505
Comments
This doesn't sound right. You're overriding both methods and achieve the same behavior as when you just leave them out. Would using no Or are you using another annotation like I don't like the options like I guess, the proper fix would be something like
which reduces to
when no fields are included. This only changes the broken behavior for A more conservative solution would be generating nothing (or trivial super-calling methods) when both |
yeah thats right. I just did a suggestions, because it could be that this prime is really wanted from the author. So its still configurable for the user, if he want to change this. At least, I would recommend your suggestions too:
|
Acrually, the code is even simpler, since at code generation time we have the value of if (callSuper) {
// generate 'int result = 1;'
} else {
// generate 'int result = super.hashCode();'
} Also, if no fields are present, we don't even need to create the |
I'v got problems with comparing a subclass with a superclass.
According to your doc, you generate the hashcode as follows:
The following line:
result =(result*PRIME) + super.hashCode();
modify the hashcode of the superclass, and if I use the annotation:
@EqualsAndHashCode(callSuper=true, of={})
I can't get the original hashcode of my superclass, to let the superclass and subclass be equal.
Because you always add the Prime to the hashcode
Is there an option to get the original hashcode from the superclass ?
My current workaround is to do it manually by adding the following lines:
But it could be nice, if there is an option to do it via your annotation
@EqualsAndHashCode(callSuper=true, prime=false, of={})
or
@EqualsAndHashCode(callSuper=true, prime=0, of={})
to set the prime generation number of 0
The text was updated successfully, but these errors were encountered: