In an interview it was asked from me to show the implementation of hashcode and equals method in an efficient manner so i have constructed the below pojo but the interviewer said that this is not the correct and the best implementation as it can result in an collision , can you please advise is the below implementation of hashcode is correct or not
public class Emp {
String name, job;
int salary;
public Emp(String n, String j, int s) {
this.name = n;
this.job = j;
this.salary = s;
}
public int hashcode() {
return name.hashCode() + job.hashCode() + salary;
}
public boolean equals(Object o) {
Emp e1 = (Emp) o;
return this.name.equals(e1.name) && this.job.equals(e1.job) && this.salary == e1.salary;
}
}