So ich hatte eine Aufgabenstellung gehabt: "Test your implementation by creating a function which accepts a field of Pair objects and identifies the smallest element with respect to the keys of the single pairs in the field". Hier ist meine Fortschritt, und wegen einen Fehler komme ich nicht weiter. Vielleicht kann jemand mir eine Hilfsstellung geben?
Und die ganzen Fehlermeldung
Java:
class KeyValue<K extends Comparable<? super K>, V> implements Comparable<KeyValue<K, V>> {
private K key;
private V value;
public KeyValue(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return this.key;
}
public V getValue() {
return this.value;
}
public void setKey(K key) {
this.key = key;
}
public void setValue(V value) {
this.value = value;
}
@Override
public int compareTo(KeyValue<K, V> o) {
return this.key.compareTo(o.getKey());
}
//java: unexpected type
public KeyValue<int, String> findMinKey(List<KeyValue<int, String>> keyValueList) {
if (keyValueList.isEmpty()) {
return null;
}
// Sortiere die Liste basierend auf den Schlüsseln
Collections.sort(keyValueList, new Comparator<KeyValue<int, String>>() {
@Override
public int compare(KeyValue<int, String> o1, KeyValue<int, String> o2) {
return 0;
}
});
// Das Element mit dem kleinsten Schlüssel ist das erste Element nach der Sortierung
return keyValueList.get(0);
}
public static void main(String[] args) {
//boolean isFound = false;
//meckert der Compiler unexpected type required: reference
//found: int
KeyValue<int, String> test2 = new KeyValue<int, String>(23, "b");
KeyValue<int, String> test3 = new KeyValue<int, String>(24, "b");
int comparisonResult = test2.compareTo(test3);
KeyValue<int, String> min = test2.findMinKey((List<KeyValue<int, String>>) test3);
System.out.println("Comparison Result: " + comparisonResult);
System.out.println("der kleinste Wert " + min);
}
}
Und die ganzen Fehlermeldung
Code:
java: unexpected type
required: reference
found: int