Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Eq {
- static class A {
- static int j = 1;
- int i;
- A(int i) {
- this.i = i;
- }
- @Override
- public int hashCode() {
- return ++j;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- A other = (A) obj;
- return i == other.i;
- }
- }
- @Test
- void testEquals() {
- A a1 = new A(1);
- A a2 = new A(1);
- assertTrue(a1.equals(a2));
- assertTrue(Objects.equals(a1, a2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment