posted 7 years ago
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>)