What rules govern such unexpected behaviour?
int i1 = -+0007;
int i2 = +-0007;
System.out.println(i1); // output: -7
System.out.println(i2); // output: -7
int i3 = +-+0007; // -7
int i4 = -+-0007; // 7
I understand that unary sign operator is right-associative. But if minus goes first (rightmost), it seems that next plus (to the left) does not change sign from minus to plus (i.e. does nothing!). But second minus changes sign (from negative to positive).
Besides we cannot use ++ or -- anywhere in this sequence of +-+-+- (+--+ is compile error: rightmost + (or leftmost +) is wrong operand of -- operation).