Java object < = relational operator check
•
Java
In Java, when = = is used to compare two objects, their references are also compared But what happens when other relational operators are used for comparison? For example:
Integer a = new Integer(10); Integer b = new Integer(9); if (a >= b) { System.out.println("A is greater"); }
When I run this, I get the output because a is bigger. Why? References are not compared, or what have they done, is it just a coincidence?
In addition, if one of the parameters is original, will the non original parameters be unpacked as primitives for such comparison?
Solution
In your example, the integer is unboxed to the original int (s) Reference type has no < = (or > =) comparison (no comparable, comparator or similar)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码