Comparing boxed Long values 127 and 128

后端 未结 4 1192
忘掉有多难
忘掉有多难 2020-11-27 10:48

I want to compare two Long objects values using if conditions. When these values are less than 128, the if condit

4条回答
  •  旧时难觅i
    2020-11-27 11:13

    num1 and num2 are Long objects. You should be using equals() to compare them. == comparison might work sometimes because of the way JVM boxes primitives, but don't depend on it.

    if (num1.equals(num1))
    {
     //code
    }
    

提交回复
热议问题