简体   繁体   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;
}

Hi there!, so I've done some research about similar problems and tried most of the suggestions and still nothing. 嗨!!,所以我对类似问题进行了一些研究,并尝试了大多数建议,但仍然没有采取任何措施。 I would like to know how to solve this problem because I've been stuck for a couple of hours now. 我想知道如何解决这个问题,因为我已经被困了几个小时了。

Thank you in advance :) 先感谢您 :)

A couple solutions: 几个解决方案:

  • data.compareTo(this.data) < 0
  • data.intValue() < this.data.intValue()

Generally speaking, you can't use < on boxed integers. 一般来说,您不能在装箱的整数上使用< Additionally, == will do the wrong thing, so you should be writing 此外, ==会做错事,因此您应该在编写

if (this.data.equals(data))
    return this;

or 要么

if (this.data.intValue() == data.intValue())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM