Reputation: 193
I am implementing my own LinkedList
. I've a class which calls MyLinkedLlist
, inside MyLinkedList
only size()
and iterator()
have been implemented. Besides I've one Abstract class where all my other necessary functions for LinkedList
in. The abstract class prototype is:
public abstract class MyAbstractSequentialList implements List
I wonder if I need to implement equals()
method inside my abstract class or it is already implemented for me because of I inherit List
?
Upvotes: 3
Views: 337
Reputation: 845
List
is an interface so if you want to implement in your own LinkedList
so you have to override means implement equals()
because there is contract with interface if you are implementing then you have to implements its methods as well.
Upvotes: 1
Reputation: 19492
List is an interface and equals() is not implemented in List because all methods in any interface should be abstract.
So you have to implement equals() method in your abstract class. if not, you have to implement it in any subclass which extends your abstractclass.
Upvotes: 1
Reputation: 4228
List is an interface. So, there won't be any default implementation. You can choose to implement one if you need. Note that if you override equals, you must override hashcode as well.
Upvotes: 5