i trying implement custom comparator beacon class (altbeacon) framework.
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; } });
it fails following error:
error:(176, 19) error: no suitable method found sort(list<collection<beacon>>,<anonymous comparator<beacon>>) method collections.<t#1>sort(list<t#1>) not applicable (cannot infer type-variable(s) t#1 (actual , formal argument lists differ in length)) method collections.<t#2>sort(list<t#2>,comparator<? super t#2>) not applicable (inferred type not conform upper bound(s) inferred: collection<beacon> upper bound(s): beacon,object) t#1,t#2 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>)
collections.sort()
sorts list inplace.
what doing passing new list, after call it's not available anymore, it's useless.
put beacons in list first, sort it, use sorted list.
Comments
Post a Comment