I'm trying to implement a Binary Search Tree, just for the sake of learning, and I want the tree to be generic. This is the code I have so far (very limited):
package lect1;
public class BinNode {
Comparable element;
BinNode left;
BinNode right;
public BinNode find(Comparable obj) {
if (element == null) {
return null;
} else if (obj.compareTo(left.element) < 0) {
left.find(obj);
} else if(obj.compareTo(right.element) > 0) {
right.find(obj);
} else {
return this;
}
return null;
}
public void insert(Comparable obj) {
}
}
However, I get the error message Unchecked call to 'compareTo(T)' as a member of raw type 'java.lang.Comparable'. Could any of you shed some light as to how I would solve this.