简体   繁体   中英

Issue with implementing methods from an interface

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM