I came across fact that Collection interface has methods equals and hashCode which are also contained in Object. Same is the case with List interface. I was having following doubts:
- Why interfaces should have these methods? Is it only because they have different meaning than those in
Object? According to this question, including these methods does not enforce the implementing class to provide their implementation as these implementations are already provided and inherited from
Object. So technically including them in the interfaces does not have any effect. This again underlines importance of first doubt, why interfaces need to have these methods?This page says:
These methods perform computations over the object’s state, but the interface, in general, has no access to state; only the implementing class has access to this state.
Which I feel further increases importance of first question.
If we at all need them in interfaces, then why Java framework dont have super-interface containing them and have such interfaces implement this interface, just like as all classes are subclasses of
Object?