I am trying to create a SkipList, and I have a method that uses a common data type:
public void add(E key, Integer value) { Node<E> p; p = find(key); }
Which will bring you here:
public Node<E> find(E key) { //Start at head Node<E> p = head; while (true) { while ( (p.getRight().getKey() != Node.posInf) && (p.getRight().getKey().compareTo(key) <= 0 )) { p.setRight(p.getRight()); } //More stuff down here } }
The problem is the compareTo() method. He says the compareTo() method is undefined for type E In Eclipse, he wants me to add two such models:
((String) p.getRight().getKey().compareTo((String) key) <= 0 )
Why does he want String ? The data type can be any. I tried to make typecast E instead, but Eclipse wants to change it to String . Any help would be appreciated.
cress source share