You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If possible, please attach source files that contain code that should and should not trigger the error. Code that should trigger the error should be in a file called PositiveCases.java, and code that should not trigger the error should be in a file called NegativeCases.java.
Otherwise, just include positive and negative cases below.
When we override equals(), we should almost always override hashCode() too.
// Positive
class Foo {
int a;
@Override
public boolean equals(Object o) {
if (o instanceof Foo) {
return a == ((Foo) o).a;
}
return false;
}
}
// Negative
class Bar {
int a;
@Override
public boolean equals(Object o) {
if (o instanceof Bar) {
return a == ((Bar) o).a;
}
return false;
}
@Override
public int hashCode() {
return a;
}
}
The text was updated successfully, but these errors were encountered:
Original issue created by maekawa@google.com on 2013-07-03 at 04:51 AM
Describe the bug pattern this checker should detect and why it is
incorrect.
Note our criteria for new checks:
https://code.google.com/p/error-prone/wiki/NewCheckCriteria
If possible, please attach source files that contain code that should and
should not trigger the error. Code that should trigger the error should
be in a file called PositiveCases.java, and code that should not trigger
the error should be in a file called NegativeCases.java.
Otherwise, just include positive and negative cases below.
When we override equals(), we should almost always override hashCode() too.
// Positive
class Foo {
int a;
@Override
public boolean equals(Object o) {
if (o instanceof Foo) {
return a == ((Foo) o).a;
}
return false;
}
}
// Negative
class Bar {
int a;
@Override
public boolean equals(Object o) {
if (o instanceof Bar) {
return a == ((Bar) o).a;
}
return false;
}
@Override
public int hashCode() {
return a;
}
}
The text was updated successfully, but these errors were encountered: