Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:27:29+00:00 2026-05-25T21:27:29+00:00

I have the following interface: interface IBasicListNode<T> { /** * Returns the current element

  • 0

I have the following interface:

interface IBasicListNode<T> {
  /**
   * Returns the current element
   */
  public T getElement();

  /**
   * Gets the next ListNode. Returns null if theres no next element
   */
  public IBasicListNode<T> getNext();

  /**
   * Sets the next ListNode 
   */
  public void setNext(IBasicListNode<T> node);
}

And a class:

class BasicListNode<T> implements IBasicListNode<T> {
  protected T _elem;
  protected BasicListNode<T> _next;

  public T getElement() {
    return this._elem;
  }

  public BasicListNode<T> getNext() {
    return this._next;
  }

  public void setNext(BasicListNode<T> node) {
    this._next = node;
  }

  /**
   * Transverse through ListNodes until getNext() returns null
   */ 
  public BasicListNode<T> getLast() {
    BasicListNode<T> tmp = this;
    while (tmp != null) {
      tmp = tmp.getNext();
    }
    return tmp;
  }
}

And I got the folloeing error:

jiewmeng@JM-PC:/labs/Uni/CS1020/Lab/03/prob 2/LinkedList$ javac BasicListNode.java 
BasicListNode.java:1: BasicListNode is not abstract and does not override 
abstract method setNext(IBasicListNode<T>) in IBasicListNode

class BasicListNode<T> implements IBasicListNode<T> {
^

Why isn’t java detecting that BasicListNode<T> implements IBasicListNode<T>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:27:30+00:00Added an answer on May 25, 2026 at 9:27 pm

    The problem here is that you need to implement the method:

    public void setNext(IBasicListNode<T> node);
    

    Note the type of the parameter node is in fact IBasicListNode<T> and not simply BasicListNode<T>.

    Take a look at the way ArrayList is implemented (here). It implements the Collection interface. Yet there is no addAll(ArrayList<T> list) method. Instead it must implement the Collection interface and thus it must implement a addAll(Collection<? extends E> c) method.

    In you example you want to change your interface to read as follows:

    public void setNext(IBasicListNode<T> node);
    

    Then implement the method in your BasicListNode class as follows:

    public void setNext(IBasicListNode<T> node) {
        this._next = node;
    }
    

    *Note: Your _next variable must now be of type IBasicListNode<T> or you must some how check for and cast to BasicListNode.

    EDIT:
    To be clear ArrayList could in fact contain a method called addAll(ArrayList<T> list) if it wanted to but that is optional. However, it absolutely must contain a method called addAll(Collection<? extends E> c) in order to fully implement the Collection interface.

    The take away of the story is that when implementing an interface your class must contain a method signature that is identical to the interface it is implementing. That is it must have the same return type, the same method name and the parameter list must have the same types and order.

    EDIT 2:
    To use instanceof with generics you will need to use the wildcard <?> as follows:

    if(node instanceof BasicListNode<?>) {
        this._next = (BasicListNode<T>)node;
    }
    

    This is needed as <T> is not a type that can be checked against at compile time since you don’t know what type will be used at runtime. The <?> allows you accept a BasicListNode of any type generic.

    As to why the getNext() method works despite having a slightly different return type has to do with the power of generics. There are a lot of special cases when using generics and requires a little more time to understand it all. For more details I would recommend looking up generics and perhaps taking a look at this post here. The accepted answer will only make things a little more confusing so I recommend taking a look at the second answer provided by Cam

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have the following interface: public interface A { public void b(); }
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
Suppose an example. I have following interface: public interface DataSource<T> { Future<T> fetch(); }
I have this following interface : public interface FruitDetails { public String getFruitName(); }
I have the following interface: public interface PluginInterface<T> where T : MyData { List<T>
Assuming that I have the following interface and class: public interface IFooRepo : IDisposable
Let's say that I have the following interface: public interface IMyService { void SimpleMethod(int
Example, I have the following interface and classes: public interface IRole { DateTime Since
I have the following interface: public interface ILogger { void Debug(string message, params object[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.