2

Possible Duplicate:
What is the difference between += and =+?

Apparently =+ is a valid operator. Where would you use it?

Example:

int j, k = 0;
j =+ k;
Community
  • 1
  • 1
  • 18
    I'd say, it is the same as `j = +k`. So, `=+` is not an operator, it is poor formatting. – Felix Kling Nov 01 '11 at 13:21
  • 4
    There is already a question about that: http://stackoverflow.com/questions/2939023/what-is-the-difference-between-and – Till Helge Nov 01 '11 at 13:23
  • 2
    This reminds me of the question about the C++ long-arrow operator: `for (int i = 10; i --> 0;) { }` (http://stackoverflow.com/questions/1642028/what-is-the-name-of-this-operator) – Michael Myers Nov 01 '11 at 14:34

2 Answers2

6

This is not a comparison operator, it is simple assignment. You are just adding a sign to your variable. If you added a -, it would negate it.

smp7d
  • 4,947
  • 2
  • 26
  • 48
0

Also another important aspect of the combined operators like =+ or =- is the fact they add an implicit cast. This is vital when you are doing operations on bytes (for example). \

byte a = 1;
byte b = 2;

a += b; //this is valid add operation

Note: the sum of two bytes is an int value, unless you do a cast.

a =(byte) a + b //but with the compound assignment you dont have to include the cast.
Mechkov
  • 4,294
  • 1
  • 17
  • 25