I was programming something and I was making a less than or equals operator and I was about to press the equals sign but I was accidentally holding down the Shift key so it made a plus sign. And it made this: <+ and IntelliJ isn't saying that it's an error so I just want to know what <+ does.
I tried looking it up online but I didn't really see anything about it
if (Integer.toString(data.getPhoneNumber()).length() <+ 10)
I thought it would give me an error or something.
It's just the spacing that makes it look special. Here's more traditional spacing:
if (Integer.toString(data.getPhoneNumber()).length() < +10)
which is
if (Integer.toString(data.getPhoneNumber()).length() < 10)
because the unary +
doesn't do anything when applied to an int
(10
is an int
in that code).
From JLS§15.15.3:
15.15.3. Unary Plus Operator
+
The type of the operand expression of the unary
+
operator must be a type that is convertible (§5.1.8) to a primitive numeric type, or a compile-time error occurs.Unary numeric promotion (§5.6.1) is performed on the operand. The type of the unary plus expression is the promoted type of the operand. The result of the unary plus expression is not a variable, but a value, even if the result of the operand expression is a variable.
At run time, the value of the unary plus expression is the promoted value of the operand.
(their emphasis)
In that case, the + operator simple specifies that the number 10 is positive: +10, as - would mean that is negative: -10. It doesn't matter if is away from it or close like: + 10, is the same as +10. But since the numbers that don't have a - (minus) sign are by default positive, the + sign is not necessary there. The < operator doesn't mind that + sign because it knows it belongs to that positive number.
If it was with a minus like this:
if (Integer.toString(data.getPhoneNumber()).length() < -10)
Then the program would compare the length() of the phone number to see if it is less than negative 10, which wouldn't make sense for the length of a telephone number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With