Skip to content

Instantly share code, notes, and snippets.

@LeoHeo
Last active June 10, 2018 03:31
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 LeoHeo/e769b1e651ca43f4531868d7fe4500ce to your computer and use it in GitHub Desktop.
Save LeoHeo/e769b1e651ca43f4531868d7fe4500ce to your computer and use it in GitHub Desktop.
package io.github.leoheo.equals;
/**
* @author Heo, Jin Han
* @since 2018-06-10
*/
public class Student {
private Long id;
private String name;
public Student(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package io.github.leoheo.equals;
public class Main {
public static void main(String[] args) {
Student leo1 = new Student(1L, "Leo");
Student leo2 = new Student(1L, "Leo");
System.out.println("leo1 hashcode => " + leo1.hashCode()); // 1625635731
System.out.println("leo2 hashcode => " + leo2.hashCode()); // 1580066828
System.out.println("leo1.equals(leo2) => " + leo1.equals(leo2)); // false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment