I'm having issues implementing a Priority Queue in Java, namely with generic Array instantiation. I've got a basic class which represents each entry in the queue:
class Node<K, V> {
K key;
V value;
Node(K key, V value) {
this.key = key;
this.value = value;
}
}
Additionally, I've got my PQ class:
public class PriorityQueue<Node> {
private Node[] data;
PriorityQueue(Class<Node> type, int size) {
data = (Node[]) Object[size];
}
}
I keep getting ClassCastException errors when trying to create the array. Any help would be greatly appreciated.