簡體   English   中英

對於參數類型java.lang.Integer,java.lang.Integer,運算符<是未定義的

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM