Skip to content

Instantly share code, notes, and snippets.

@takahashi-h5
Last active August 31, 2019 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takahashi-h5/66398e7cf9d19957408fcf7ebfcd0125 to your computer and use it in GitHub Desktop.
Save takahashi-h5/66398e7cf9d19957408fcf7ebfcd0125 to your computer and use it in GitHub Desktop.
public class Employee {
private int age;
private String name;
public Employee(int age, String name) {
this.age = age;
this.name = name;
}
public boolean equals(Object obj) {
if(obj == null) return false; // パラメータがnullの場合はfalseを返すのがequalsメソッドの条件
return this.name == ((Employee)obj).name; // nameだけ同値ならtrueとしている
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment