Skip to content

Instantly share code, notes, and snippets.

@ababup1192
Created March 21, 2020 07:04
Show Gist options
  • Save ababup1192/5ba0db5566b51e47c290a8495d54852d to your computer and use it in GitHub Desktop.
Save ababup1192/5ba0db5566b51e47c290a8495d54852d to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String args[]) {
Point p1 = new Point(1, 1);
Point p2 = new Point(2, 3);
Point p3 = new Point(1, 1);
// false
System.out.println(p1.equals(p2));
// true
System.out.println(p1.equals(p3));
}
}
public class Point {
// フィールド
private int x;
private int y;
// コンストラクタ
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public boolean equals(Object object) {
if (object == null || !(object instanceof Point)) {
return false;
}
Point target = (Point) object;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment