3

I need to explain this strange operator =+ (equal plus)

Example #1:

Double a = new Double(5);
Double b = new Double(10);
a += b

result:

a=15.0
b=10.0

Example #2:

Double a = new Double(5);
Double b = new Double(10);
a =+ b

result:

a=10.0
b=10.0

I understand the first example, but please explain me what this =+ operator did in example no.2.

And another interesting fact is, that these operators are valid and compilable: +=, -=, *=, /=
but any of these two won't compile: =*, =/

user1610458
  • 311
  • 1
  • 5
  • 18

1 Answers1

5

=+ is the assignment operation and the unary + afterwards. It's perfectly valid and what happens is:

a = (+b); 

It's pretty much the same when you want to assign the negative value of a variable to another variable:

a = (-b); //a will be assigned with -10

Also, =* doesn't compile, because there's no * unary operator.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147