I want to create a class lets say Employee that implements the generic interface Comparable and overrides the methods equals, hashCode, and toString…How would I be able to do it ?
would this be ok
interface MinMax<T extends Comparable<T>> {
T equals();
T hashCode();
T toString();
}
and
class Employee<T extends Comparable<T>> implements MinMax<T> {
public T equals(){
}
public T hashCode(){
}
public T toString(){
}
}
There are two parts to the question.
Part 1: Override equals, hashCode and toString.
Simply redefine those methods in you new class with your new implementation.
Part 2: Implement the Comparable interface.
I assume you wish to compare to other employees. Declare that it implements Comparable, and implement the compareTo method described by the interface.