i think, you are right there is no need , because there is no hashing involved in case of TreeMap, but as per java contract if you are overriding equals method, then hash code should also be overridden, this makes sense as in future if you switch to Hashmap from treemap, your code will run as good as it is now
Purpose of overriding hashCode() and equals() methods is to change the behaviour of a class in sorting and comparison.
It is not mandatory to override these methods in all classes when used as key to a map. It depends on requirement. But if you override equals() method then hashCode() for two equal objects must return same value.
Please see Object.hashCode() method in J2SE API documentation.
Does that mean TreeMap never uses equals(...) and hashCode() methods?
equals() and hashCode() usage in TreeMap class is different than equals() and hashCode() method usage in the class that is used as a key in a TreeMap.
What is equals() and compareTo() compatibility?
equals() method is to compare two objects for equality and compareTo() is used to compare one object with the another object for order.
I am using TreeMap, it never concerns with equals(...) as I see. Is is sure the TreeMap never uses equals(...) and hashCode() methods?
Keys in TreeMap must be comparable i.e. either the class used as key must implement comparable interface (referred as class's natural ordering) or supply a comparator (comaprison function) to TreeMap constructor.
Comparing is commonly used for ordering and not necessarily same as equals.
TreeMap cares about comparing keys for ordering purpose.