[英]The operator < is undefined for the argument type(s) java.lang.Integer, java.lang.Integer
public TreeNode find(Integer data){
if (this.data == data)
return this;
if (data < this.data && leftChild != null)
return leftChild.find(data);
if (rightChild != null)
return rightChild.find(data);
return null;
}
嗨!!,所以我對類似問題進行了一些研究,並嘗試了大多數建議,但仍然沒有采取任何措施。 我想知道如何解決這個問題,因為我已經被困了幾個小時了。
先感謝您 :)
幾個解決方案:
data.compareTo(this.data) < 0
data.intValue() < this.data.intValue()
一般來說,您不能在裝箱的整數上使用<
。 此外, ==
會做錯事,因此您應該在編寫
if (this.data.equals(data))
return this;
要么
if (this.data.intValue() == data.intValue())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.