繁体   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