I'm currently studying a course in data structures & algorithms, and we have got an assignment from our teacher to create a hashtable with chaining as a collision resolution technique.
For each entry in the hash table our teacher wants us to have this equals method:
@Override
public boolean equals(Object obj) {
Entry keyToCompare = new Entry(obj, null);
return key.equals(keyToCompare.key);
}
What is the difference when writing it like this compared to if I just compare the keys with the regular .equals?
Here is the complete class:
public class Entry<T> {
private Object key;
private Object value;
public Entry(T key, T value){
this.key = key;
this.value = value;
}
public boolean equals(Object obj){
//What i think should work
return key.equals(obj);
}
}