Ich versuche, einen benutzerdefinierten Komparator für Beacon-Klasse (AltBeacon) Framework zu implementieren.IMplementing benutzerdefinierten Komparator
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;
}
});
Es schlägt mit folgenden Fehler:
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>)
Dies kann helfen - Typ zu Ihrem Arrays.asList (Beacons) Anruf hinzufügen: http://stackoverflow.com/questions/15799359/is-there-a-way-to-force-the-return-type-of -arrays-aslist –
Es sieht so aus, als wäre 'beacons' bereits ein 'Collection'-Objekt, also warum in eine' List'? –