0

I'm quite new to Java and I've just encountered an issue with implementing methods from an interface. I tried to search this up online but couldn't find the solution I needed. A simple version of my code is as follows:

Interface:

public interface LinkedList<E> { 
    public int size();
}

Class:

public class SinglyLinkedList<E> implements LinkedList<E> {
    public int size = 0;

    @Override
    public int size() {
        return size;
    }
}

I'm currently using eclipse and it is suggesting that I remove the @Overide tag above the method. When I do, however, it gives me another error claiming that "The method size() of type SinglyLinkedList must override or implement a supertype method." I'm not quite sure what the "supertype method" is referring to.

I'd be much appreciated if someone could explain to me how this should be fixed.

Thanks in advance!

2
  • 1
    Your code works perfectly fine for me. I strongly suspect that the LinkedList your class is implementing is not the one have defined. Try changing the name to MyLinkedList to test that theory. Commented Nov 17, 2020 at 23:10
  • which java version are you using? Commented Nov 17, 2020 at 23:11

1 Answer 1

2

It happens often in Eclipse to give you this error and the solution happens to be restarting the Application. Helped me many times personally.

If it won't solve your issue:

In Eclipse:

  1. Go to the Properties of the Java project in Eclipse
  2. Go to the Java Compiler menu
  3. Check that the Compiler Compliance Level is set to 1.5 or higher

If it won't resolve the issue - upload your code somewhere and give us a link or even give the code in there and we will try to fix it.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.