What is the difference between += and =+? Specifically, in java, but in general also.
The += operation as you said, is used for increment by a specific value stated in the R value.Like,
i = i+1;
//is equivalent to
i += 1;
Whereas, =+ is not any proper operation, its basically 2 different operators equal and unary plus operators written with each other.Infact the + sign after = makes no sense, so try not to use it.It will only result in a hocum.
i =+ 1;
//is equivalent to
i = +(1);
+=
is an operator that increments the left-hand side of the assignment by the value of the right-hand side and assigns it back to the variable on the left-hand side. =+
is not an operator but, in fact, two operators: the assignment operator =
and the unary plus +
(positive) operator which denotes the value on the right-hand side is positive. It's actually redundant because values are positive unless they are negated with unary minus. You should avoid the =+
construct as it's more likely to cause confusion than do any actual good.
+=
is get and increment:
a += 5; // adds 5 to the value of a
=+
isn't really a valid identifier on its own, but might show up when you're using the unary +
operator:
a =+ 5; // assigns positive five to a