Why does this Java code with “+ +” compile?

后端 未结 8 837
梦毁少年i
梦毁少年i 2020-12-10 10:25

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)
    {
         


        
8条回答
  •  一生所求
    2020-12-10 11:11

    In this case, Java considers the + operator as a unary operator and hence the result is 10. Just try with the following code:

    int e = + - 10; // result is -10
    int e = - - 10; // result is 10
    

提交回复
热议问题