fork download
  1. class Point {
  2. protected int x, y;
  3.  
  4. public boolean equals(Object o) {
  5. if (o == null) return false;
  6. if (o.getClass() != Point.class) return false;
  7. Point other = (Point)o;
  8. return other.x == x && other.y == y;
  9. }
  10.  
  11. public int hashCode() {
  12. return x * 31 + y;
  13. }
  14. }
  15.  
  16. class BuggyInit {
  17. public static void main (String[] args) {
  18. Point a = new Point();
  19. a.x = 3;
  20. a.y = 5;
  21.  
  22. Point b = new Point() { { x = 3; y = 5; } };
  23.  
  24. System.out.println("a.x == b.x ? " + (a.x == b.x));
  25. System.out.println("a.y == b.y ? " + (a.y == b.y));
  26. System.out.println("a == b ? " + a.equals(b));
  27. System.out.println("b == a ? " + b.equals(a));
  28. }
  29. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
a.x == b.x ? true
a.y == b.y ? true
a == b ? false
b == a ? true