• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparator Interface issue: Inferred type doesn't conform to upper bound

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am trying to figure out how to use a comparator to sort 2 arrays, v[] and w[], based on their ratios of v[i]/w[i].  



Here error msg I got  and it is confusing to me.  Any help is greatly appreciated!

error: no suitable method found for sort(Double[],<anonymous Comparator<Integer>>)
   Arrays.sort(arr, new Comparator<Integer>() {
         ^
   method Arrays.<T#1>sort(T#1[],Comparator<? super T#1>) is not applicable
     (inferred type does not conform to upper bound(s)
       inferred: Double
       upper bound(s): Integer,Object)
   method Arrays.<T#2>sort(T#2[],int,int,Comparator<? super T#2>) is not applicable
     (cannot infer type-variable(s) T#2
       (actual and formal argument lists differ in length))
 where T#1,T#2 are type-variables:
   T#1 extends Object declared in method <T#1>sort(T#1[],Comparator<? super T#1>)
   T#2 extends Object declared in method <T#2>sort(T#2[],int,int,Comparator<? super T#2>)


--------------------------------------------------------------------------------
Just in case you need more info, here is the error msg in verbose mode:

error: no suitable method found for sort(Double[],<anonymous Comparator<Integer>>)
   Arrays.sort(arr, new Comparator<Integer>() {
         ^
   method Arrays.sort(int[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(int[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(long[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(long[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(short[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(short[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(char[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(char[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(byte[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(byte[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(float[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(float[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(double[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(double[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(Object[]) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.sort(Object[],int,int) is not applicable
     (actual and formal argument lists differ in length)
   method Arrays.<T#1>sort(T#1[],Comparator<? super T#1>) is not applicable
     (inferred type does not conform to upper bound(s)
       inferred: Double
       upper bound(s): Integer,Object)
   method Arrays.<T#2>sort(T#2[],int,int,Comparator<? super T#2>) is not applicable
     (cannot infer type-variable(s) T#2
       (actual and formal argument lists differ in length))
 where T#1,T#2 are type-variables:
   T#1 extends Object declared in method <T#1>sort(T#1[],Comparator<? super T#1>)
   T#2 extends Object declared in method <T#2>sort(T#2[],int,int,Comparator<? super T#2>)
 
Wayne Volkov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found the solution to my question.  All I need to do is to make the following change to fix the inferred bound error.

Double[] arr = new Double[len];  //wrong

Integer [] arr = new Integer[len];  //correct
 
reply
    Bookmark Topic Watch Topic
  • New Topic