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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:43:55+00:00 2026-06-14T05:43:55+00:00

Here is the case, I have two classes A , B , and a

  • 0

Here is the case, I have two classes A, B, and a generic interface C

Class A implements Comparable<A> {...}

interface C<T> {...}

//this class is not longer generic type, I do not know if this matter.
Class B extends A implements C<A> {...} 

Then, at other class, I got a B List and sort it as follow

List<B> list = new ArrayList<B>();
Collections.sort(list);

This works perfectly, but now I would like to change the list of B to the generic interface C, so that it can be more general.

List<C<A>> list = new ArrayList<C<A>>();
Collections.sort(list);

This time I got the Error as follow:

Bound mismatch: The generic method sort(List<T>) of type Collections is not
applicable for the arguments (List<C<A>>). The inferred type C<A> is not a
valid substitute for the bounded parameter <T extends Comparable<? super T>>

I have tried the following modifications (of course does not work):

  1. change C to interface C<T> extends Comparable<T>{...}
  2. change B to class B extends A implements C<A>, Comparable<T> {...}

Can anybody help me?

  • 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-14T05:43:56+00:00Added an answer on June 14, 2026 at 5:43 am

    change C to interface C extends Comparable{…}
    Class B extends A implements C {…}

    As you would have already seen from the error messages, these two won’t work together as there will be a conflict in B‘s definition w.r.t to Comparable<A> and Comparable<C<A>>.

    Since A is already implementing Comparable<A>, you can achieve the following

    List<C<A>> list = new ArrayList<C<A>>();
    Collections.sort(list);
    

    by defining a Comparator for C<A> as follows:

    class CTComparator<T> implements Comparator<C<T>>
    {
        @Override
        public int compare(C<T> o1, C<T> o2)
        {
            return 0;
        }
    }
    

    and then applying the sort method with this comparator:

    List<C<T>> list  = new ArrayList<C<T>>();
    Collections.sort(list, comparator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. I have two classes, in this case A and
Let us assume we have the two following classes: abstract case class MyParent(param: Int)
I have read here http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ about how you probably shouldn't be trying to un-flatten
I have two classes, derived from a common class. The common class has a
I defined two classes: class Token_ { public: virtual char operator*()const = 0;//this fnc
I know that you're not allowed to inherit from case classes but how would
Let just say that we have two classes, A and B . Here is
I have two classes, a Teacher class and a Student class. In my program
I have two different classes that have the same class as a private field.
If I have for example two classes A and B , such that class

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.