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 7778127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:19:09+00:00 2026-06-01T18:19:09+00:00

I am trying to using the compareTo method for a generic Node type E.

  • 0

I am trying to using the compareTo method for a generic Node type E.

I have already bound E to Comparable

public class LinkedList<E extends Comparable<E>> {

    //  ----------------------------------------------------------
    //  Implementing the doubly linked nodes (static nested class)
    //  ----------------------------------------------------------

    private static class Node<E extends Comparable<E>> {

This method isSorted is implemented within the LinkedList class, the Node class is within the Linkedlist class.

I keep getting a compilation error “The method compareTo(LinkedList.Node) is undefined for the type LinkedList.Node”

I believe that only pops up when E is not extending Comparable, in my case it is.
Any help?

 public boolean isSorted( ){

        if(!isEmpty()){

        Node<E> temp = head;
        boolean local = true;
        int x=0;
        while (temp.next != null){
          x=temp.compareTo(temp.next);
          if(x<0){
            temp = temp.next;}
          else {return local;}

        }
        return local;}
        else{ throw new IllegalArgumentException();}
      }

I checked this thread already, How to compare generic nodes in a linked list using Comparable?

It didn’t help.

Thank you in advance

Mjall2

  • 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-06-01T18:19:10+00:00Added an answer on June 1, 2026 at 6:19 pm

    You’re trying to compare the nodes, when it’s only the values inside the nodes that are Comparable. Instead of temp.compareTo(temp.next), you probably want something like temp.value.compareTo(temp.next.value).

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

Sidebar

Related Questions

I am trying to implement generics in Java using Comparable<T> interface. public static <T>
Trying to write my first generic class in C#: public class HighScoreList<ScoreType> where ScoreType
I am trying to compare a value which was grabbed using the get method
I'm using (trying to use) jQuery to add a class to the first paragraph
I'm trying to write a Compare method to compare properties in some POCOs using
I am trying to use the Except method on a LINQ result set using
I have two structs, in which I'm trying to overwrite a method in the
i'm trying to implement a login method for mongodb , using python (pymongo) and
I'm trying to implement the equals method in my class.. notice: the ' _data
I'm trying to write a method to compare two arrays in Java without using

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.