The code is as following:
public class Main {
public static void main(String[] args) {
Student a = new Student(10, "Ole");
Student b = new Student(10, "Ole");
System.out.println(a.hashCode());
System.out.println(b.hashCode());
}
}
and the object looks like this:
public class Student {
private int snr;
private String namn;
public Student(int snr, String namn) {
this.snr = snr;
this.namn = namn;
}
}
These are the results when running the code:
57651960
441366923
I've read some of the javadoc, but I can't find out why, can anyone explain why this happens? And also what I would have to do to make the result identical? (if at all possible)
Thanks for the explanations :)! Makes sense now ;)