-1

次の問題が発生しました Exception in thread "main" java.lang.ClassCastException: java.lang.ref.SoftReference cannot be cast to java.lang.Comparable

以下のコードで。ご協力ありがとう御座います!

PriorityQueue<SoftReference<Element<K, V>>> heap;
heap.add(new SoftReference<Element<K, V>>(newElement));

クラス要素の定義は次のとおりです

class Element<K, V> implements Comparable<Element<K, V>>{
        long timeStamp;
    K key;
    V val;
    @Override
    public int compareTo(Element<K, V> o) {
    return new Long(timeStamp).compareTo(o.timeStamp);
    }
    Element(long ts, K key, V val){
        this.timeStamp = ts;
        this.key = key;
        this.val = val;
        }
}
4

1 に答える 1

1

PriorityQueueカスタムなしで作成されたはComparator、その要素が を実装することを期待していますが、実装ComparableしてSoftReferenceいません。比較できるPriorityQueueカスタムであなたのを作ってみてください。ComparatorSoftReference

于 2013-08-17T17:11:16.647 に答える