3

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?

4
  • when i write "public abstract class MyAbstractSequentialList implements List" eclipse show me some methods but not equals(). Commented Apr 5, 2012 at 6:01
  • actually how can compiler says if i need or not implement equals() method,because it is up to me? Commented Apr 5, 2012 at 6:05
  • there is no error when i didn't implement equals() method..when i call it for testing it works but returns false which shouldn't be the result Commented Apr 5, 2012 at 6:07
  • My bad, I expected a compile-time warning. Noise deleted. Hope you get a suitable answer. :) Commented Apr 5, 2012 at 6:29

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.