I got the following exception in my code: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Comparable; cannot be cast to [LElement; at the following call:
Element<K,V>[] heap = (Element<K,V>[]) new Comparable[size];
where Element is defined as follows:
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;
}
}
any help is greatly appreciated!
heap = (K[]) new Comparable[capacity];
– user2692465 Aug 17 '13 at 19:31Element<K, V>[] heap = (Element<K, V>[]) new Element[size];
? – sbat Aug 17 '13 at 20:06