7

Is += the same as =+?

I can't find any reason for why the plus sign is reversible. For what reasons would I need to use one of the other? Where can i find docs on this i tried searching but didnt see the use of both.

117
  • 167
  • 1
  • 2
  • 7
  • 1
    [There is no such operator](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) – fge Jul 12 '15 at 09:06

1 Answers1

24

It's not the same.

x+=5 is equivalent to x=x+5.

x=+5 (or x=(+5)) is equivalent to x=5.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • 4
    Note that `x+=5` is only _mostly_ equivalent to `x=x+5`. The `+=` operation also casts, even lossily if necessary. For example, `int x = 3; x += 5.9;` compiles, whereas `int x = 3; x = x + 5.9;` does not. – ctrueden Nov 05 '18 at 17:32