Java's unary plus operator appears to have come over from C, via C++.
int result = +1;
It appears to have the following effects:
- Unboxes its operand, if it's a wrapper object
- Promotes its operand to
int
, if it's not already an int
or wider
- Complicates slightly the parsing of evil expressions containing large numbers of consecutive plus signs
It seems to me that there are better/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."
However, in Java, one cannot overload any operator. So does this unary plus operator exist in Java only because it existed in C++?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…