-1
我試圖實現一個二進制搜索樹,只是爲了學習,我希望樹是通用的。這是代碼我迄今(非常有限):未檢查調用'compareTo(T)'
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) {
}
}
然而,我去「的compareTo(T)」作爲原始類型「java.lang.Comparable的」中的一員的錯誤消息未檢查呼叫。你們中的任何一個人都可以告訴我如何解決這個問題。
http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it – 2014-11-21 16:34:40