java - <+ 在 Java 中是什么意思?

标签 java bitwise-operators operator-keyword

<分区>

我正在编写一些东西,我正在制作一个小于或等于运算符,我正要按下等号,但我不小心按住了 Shift 键,所以它变成了一个加号。它是这样的:<+ 并且 IntelliJ 并没有说这是一个错误,所以我只想知道 <+ 做了什么。

我试着在网上查了一下,但我真的没有看到任何关于它的信息

if (Integer.toString(data.getPhoneNumber()).length() <+ 10)

我以为它会给我一个错误或什么的。

最佳答案

只是间距让它看起来很特别。这是更传统的间距:

if (Integer.toString(data.getPhoneNumber()).length() < +10)

这是

if (Integer.toString(data.getPhoneNumber()).length() < 10)

因为一元 + 在应用于 int 时不执行任何操作(10int在该代码中)。

来自 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.

(他们的重点)

关于java - <+ 在 Java 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56101017/

相关文章:

c - C 中的 stdbool.h bool 类型按位异或 ^ 和赋值

ruby - 如何处理 []+= 组合以在 Ruby 中自动激活散列?

c++ - 命名空间和运算符解析

java - 静态如何操作?

java - 如何构建与 Spring Elasticsearch 存储库中的短语之一匹配的查询

java - 在 Java 上做初学者类(class),遇到 do-while 和 if-else 循环以及字符串验证问题

java - Quartz 作业中的 RequestedScope

java - 如果节点上有多个更改,ZooKeeper 是否会跳过向订阅者发出警报?

algorithm - 在大型集合中有效地找到具有低汉明距离的二进制字符串

c# - 校验和中的 "int &= 0xFF"有什么作用?