-
Notifications
You must be signed in to change notification settings - Fork 75
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
Option to ignore non-final fields expected to be used for equals #200
Labels
Comments
Hi Alex,
That sounds like a good idea.
I'm on holiday now so I'll get back to you about this later!
…On Thu, Jul 12, 2018, 12:20 Alex Bikadorov ***@***.***> wrote:
Considering this simple example (almost auto-generated by IDE):
public class Foo {
private final long id;
private final String name;
private String description = "";
public Foo(long id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@OverRide
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Foo foo = (Foo) o;
return id == foo.id && Objects.equals(name, foo.name);
}
@OverRide
public int hashCode() {
return Objects.hash(id, name);
}
}
EqualsVerifier.forClass(Foo.class).usingGetClass().verify(); does fail
with
java.lang.AssertionError: Significant fields: equals does not use
description, or it is stateless.
I follow the common practice to not use non-final fields for equals
(insert foos into a set and later modify them -> ugh!).
Now there is the option to explicitly tell EqualsVerifier the fields used
in equals -> not practical if EqualsVerifier should be used for 100+
already existing classes. Or suppress(Warning.ALL_FIELDS_SHOULD_BE_USED),
but this does not differentiate between final and non-final fields.
So i kindly propose a new
suppress(Warning.ALL_NON_FINAL_FIELDS_SHOULD_BE_USED).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#200>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA0osSSBLlWpqi_6SaokboF1Mw0PNOKlks5uFz8jgaJpZM4VMvqu>
.
|
jqno
added a commit
that referenced
this issue
Jul 30, 2018
I just released version 2.5 with a |
Thanks for the fast implementation! |
akhalikov
pushed a commit
to akhalikov/equalsverifier
that referenced
this issue
Nov 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Considering this simple example (almost auto-generated by IDE):
EqualsVerifier.forClass(Foo.class).usingGetClass().verify();
does fail withI follow the common practice to not use non-final fields for equals (insert foos into a set and later modify them -> ugh!).
Now there is the option to explicitly tell EqualsVerifier the fields used in equals -> not practical if EqualsVerifier should be used for 100+ already existing classes. Or
suppress(Warning.ALL_FIELDS_SHOULD_BE_USED)
, but this does not differentiate between final and non-final fields.So i kindly propose a new
suppress(Warning.ALL_NON_FINAL_FIELDS_SHOULD_BE_USED)
.The text was updated successfully, but these errors were encountered: