为什么这个Java代码带有“+ +”编译? [英] Why does this Java code with "+ +" compile?
本文介绍了为什么这个Java代码带有“+ +”编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇为什么这个简单的程序可以使用IntelliJ(Java 7)由java编译。
I'm curious why this simple program could be compiled by java using IntelliJ (Java 7).
public class Main {
public static void main(String[] args)
{
int e = + + 10;
System.out.println(e);
}
}
输出仍为10.这是什么意思 + + 10
?
The output is still 10. What is the meaning of + + 10
?
推荐答案
一元加上,两次。它不是前缀增量,因为有空格。 Java在很多情况下确实考虑了空格。
It is the unary plus, twice. It is not a prefix increment because there is a space. Java does consider whitespace under many circumstances.
一元加上基本上什么也没做,它只是提升了操作数。
The unary plus basically does nothing, it just promotes the operand.
例如,这不会编译,因为一元加号导致字节
被提升为 int
:
For example, this doesn't compile, because the unary plus causes the byte
to be promoted to int
:
byte b = 0;
b = +b; // doesn't compile
这篇关于为什么这个Java代码带有“+ +”编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文