I have an abstract class and I wanted to force all the implementations of the class to implement there own equals and hashCode method. The class has just one method which returns a String.
The abstract class is defined like this
public abstract class Type
{
public abstract String getType();
public abstract boolean equals(Object other);
public abstract int hashCode();
}
I have implemented the equals method. Now I am implementing the hashCode method for this class. I have a couple of questions:
1) Is this the right approach to override the == behavior in all implementations of the class.
2) What would be the best way to implement the hashCode method for this class which only has one function that returns a string?
Is this is a duplicate, please point me to the right answer.