Próbuję użyć Collections.sort na ArrayList niestandardowych obiektów, ale ja dostaję ostrzeżenie i nie mogę zrozumieć, dlaczegoostrzeżenie Java z realizacją Porównywalne
Warning: Type safety: Unchecked invocation
sort(ArrayList<CharProfile>) of the generic method sort(List<T>)
of type Collections
Z tym kodem:
ArrayList<CharProfile> charOccurrences = new ArrayList<CharProfile>();
...
Collections.sort(charOccurrences);
A oto moja metoda:
public class CharProfile implements Comparable {
...
@Override
public int compareTo(Object o) {
if (this.probability == ((CharProfile)o).getProbability()) {
return 0;
}
else if (this.probability > ((CharProfile)o).getProbability()) {
return 1;
}
else {
return -1;
}
}
}
Co to jest „inny” robi na początku „CompareTo()” metody? –