What is the purpose of Java’s unary plus operator?

The unary plus operator performs an automatic conversion to int when the type of its operand is byte, char, or short. This is called unary numeric promotion, and it enables you to do things like the following:

char c="c";
int i = +c;

Granted, it’s of limited use. But it does have a purpose. See the specification, specifically sections §15.15.3 and §5.6.1.

Leave a Comment