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

后端 未结 8 836
梦毁少年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:13

    10 is a literal not a variable. As such, 10 cannot be incremented.

    ++somevariable increments somevariable.
    
    ++variable -> increment operator.
    
    + + someliteral will just equate to someliteral.
    
    + + literal -> successive unary + operator
    

提交回复
热议问题