Di seguito mi dà un messaggio di errore:Java Generics: compareTo e "cattura # 1 di?"
public static List<Comparable<?>> merge(Set<List<Comparable<?>>> lists) {
List<Comparable<?>> result = new LinkedList<Comparable<?>>();
HashBiMap<List<Comparable<?>>, Integer> location = HashBiMap.create();
int totalSize;
for (List<Comparable<?>> l : lists) {
location.put(l, 0);
totalSize += l.size();
}
boolean first;
List<Comparable<?>> lowest; //the list with the lowest item to add
int index;
while (result.size() < totalSize) {
first = true;
for (List<Comparable<?>> l : lists) {
if (! l.isEmpty()) {
if (first) {
lowest = l;
}
else if (l.get(location.get(l)).compareTo(lowest.get(location.get(lowest))) <= 0) { //error here
lowest = l;
}
}
}
index = location.get(lowest);
result.add(lowest.get(index));
lowest.remove(index);
}
return result;
}
L'errore è:
The method compareTo(capture#1-of ?) in the type Comparable<capture#1-of ?> is not applicable for the arguments (Comparable<capture#2-of ?>)
cosa sta succedendo qui? Ho fatto il tipo di tutto Comparable
così ho potuto chiamare .compareTo
e ordinare questa lista. Sto usando i farmaci generici in modo errato?
Alcuni di quelli > devono essere, ma non ho tempo in questo minuto per ordinare questo in una risposta. Se nessun altro tornerò più tardi. –
bmargulies