Implementing your own LinkedList

I am implementing my own LinkedList

. I have a class that calls MyLinkedLlist

, MyLinkedList

only size()

and are implemented internally iterator()

. Also, I have one abstract class where all my other required functions are for LinkedList

in. The prototype of an abstract class is:

public abstract class MyAbstractSequentialList implements List

      

I wonder if I need to implement a method equals()

inside my abstract class or is it already implemented for me due to what I inherit List

?

+3


source to share


3 answers


The list is an interface. So there won't be any default implementation. You can choose one option if you need. Note, if you override equals, you must also override hashcode.



+5


source


List is an interface, and equals () is not implemented in List , because all methods in any interface must be abstract.



So, you have to implement equals () method in your abstract class. if not, you must implement it in any subclass that extends your abstract class.

+1


source


List

is an interface, so if you want to implement in your own LinkedList

, so you need to override the implementers equals()

, because there is a contract with the interface, if you implement, then you need to implement your methods as well.

+1


source







All Articles