What is the difference between += and =+?

后端 未结 9 1659
夕颜
夕颜 2020-12-03 14:07

What is the difference between += and =+? Specifically, in java, but in general also.

9条回答
  •  醉梦人生
    2020-12-03 15:05

    i += 4;
    

    means

    i = i + 4;  // increase i by 4.
    

    While

    i =+ 4;
    

    is equivalent to

    i = +4;   // assign 4 to i. the unary plus is effectively no-op.
    

    (See http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.15.3 for what a unary + does.)

提交回复
热议问题