Java's unary plus operator appears to have come over from C, via C++. As near as I can tell, it has the following effects:
- unboxes its operand, if it's a wrapper object
- promotes its operand to
int
, if it's not already anint
or wider - complicates slightly the parsing of evil expressions containing large numbers of consecutive plus signs
It seems to me that there are better (or, at least, clearer) ways to do all of these things.
In this SO question, concerning the counterpart operator in C#, someone said that "It's there to be overloaded if you feel the need." But in Java, one cannot overload any operator. So does this operator exist in Java just because it existed in C++?