Я пытаюсь реализовать пользовательский компаратор для рамки Beacon (AltBeacon).В дополнение к пользовательскому компаратору
Collections.sort(Arrays.asList(beacons), new Comparator<Beacon>(){
@Override
public int compare(Beacon lhs, Beacon rhs) {
double diff = lhs.getDistance() - rhs.getDistance();
if (diff > 0){
return 1;
}
if (diff < 0){
return -1;
}
return 0;
}
});
Это терпит неудачу с ошибкой при слежении:
Error:(176, 19) error: no suitable method found for sort(List<Collection<Beacon>>,<anonymous Comparator<Beacon>>) method Collections.<T#1>sort(List<T#1>) is not applicable (cannot infer type-variable(s) T#1 (actual and formal argument lists differ in length)) method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable (inferred type does not conform to upper bound(s) inferred: Collection<Beacon> upper bound(s): Beacon,Object) where T#1,T#2 are type-variables: T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>) T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)
Это может помочь - добавьте тип в свой запрос Arrays.asList (маяки): http://stackoverflow.com/questions/15799359/is-there-a-way-to-force-the-return-type-of -arrays-aslist –
Похоже, что «beacons» уже является объектом «Collection», поэтому зачем его помещать в «Список»? –