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

  • Home
  • SEARCH
  • 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 6760797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:06:27+00:00 2026-05-26T14:06:27+00:00

i have the following code that won’t compile because of generic problems. It comes

  • 0

i have the following code that won’t compile because of generic problems. It comes from when i try to run the code. The problem is that i must fix the generic issue but i can’t spot it whether i must change something in the class StAlgo or in the method.

public class StAlgo{

//signature selection sort
public <T extends Comparable<T>> int selectionSort(T[] array) {
}

 public static <T extends Comparable<T>> T[] getRandomPermutationOfIntegers(int size) {
      T[] data = (T[])new Comparable[size]; 
      for (Integer i = 0; i < size; i++) {
          data[i] = (T)i;
      }

      // shuffle the array
      for (int i = 0; i < size; i++) {
          T temp;
          int swap = i + (int) ((size - i) * Math.random());
          temp = data[i];
          data[i] = data[swap];
          data[swap] = temp;
      }
      return data;
  }

 public <T extends Comparable<T>> void trySelectionSort(){
      int N = 100, M = 100;  

      for(int i= 0; i < N; i++){
          T[] arrayInts = (T[])new Comparable[i];
          for(int j= 0; j < M; i++){
              arrayInts = getRandomPermutationOfIntegers(i);
              //Collections.shuffle(Arrays.asList(arrayInts));
              selectionSort(arrayInts);
          }
      }
  }
}







//Main class  has the folling code:

    StAlgosa s = new StAlgosa();
    s.trySelectionSort();

I get the following error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Bound mismatch: The generic method trySelectionSort() of type StAlgosa is not applicable for the arguments (). The inferred type Comparable<Comparable<T>> is not a valid substitute for the bounded parameter <T extends Comparable<T>>

how do i fix it?

thanks

  • 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-26T14:06:28+00:00Added an answer on May 26, 2026 at 2:06 pm

    This looks like a problem with Type Erasure – http://download.oracle.com/javase/tutorial/java/generics/erasure.html

    When you do T extends Foo<T>, after compilation, Java just remembers T extends Foo.

    Checkout Generic Restriction Hell: Bound Mismatch post for more information.

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

Sidebar

Related Questions

I have the following code that won't compile and although there is a way
I have following code snippet that i use to compile class at the run
I have the following code that loads a user's Active Directory DirectoryEntry object from
I have the following code that returns rows from a database when a form
I have the following code that doesn't compile. class Base { public: virtual ~Base()
I have a problem with the following example code that shows inconsistent behavior for
I have following code that does not work due to a being a value
I have the following code that shows either a bug or a misunderstanding on
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I have the following code that creates two objects (ProfileManager and EmployerManager) where the

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.