這是一個容器的實現,它可以與具有兼容密鑰的任何其他容器進行比較。我有一個奇怪的錯誤使用Java中的泛型,有什麼想法?Java通用捕獲和可比較
private static class Container
<Key extends Comparable<? super Key>, Value>
implements Comparable<Container<? super Key, ?>>
{
public Key key;
public Value value;
public Container(Key k, Value v) {
key = k;
value = v;
}
public int compareTo(Container<? super Key, ?> o) {
return key.compareTo(o.key);
}
}
...
這是錯誤:
compareTo(capture#98 of ? super Key) in
java.lang.Comparable<capture#98 of ? super Key> cannot be applied to
(java.lang.Comparable<? super capture#822 of ? super Key>)
return key.compareTo(o.key);
^
1 error
好吧,我想我理解它,問題是**?**不匹配相同的類型,但仍然不知道如何解決它我想要求每個容器cl屁股可以與任何其他具有兼容密鑰類型的容器相媲美。 – 2010-08-10 15:23:20