I have searched the web and it gives me a divide answer. Some said it is only an unary operator and some said it is an arithmetic operator. Thanks
Asked
Active
Viewed 99 times
3
-
6It's both. Things can be classified as more than one thing. – Kayaman Feb 01 '20 at 10:32
-
isn't that the same question as [In Java, is a++ a postfix operator or an unary operator?](https://stackoverflow.com/q/60014618/85421)? – user85421 Feb 01 '20 at 10:56
-
@Kayaman I'd argue that it's also an assignment operator, because it assigns a new value to the variable. – Andy Turner Feb 01 '20 at 11:09
2 Answers
3
These classifications don't contradict each other.
++
is an unary operator, as it applies to a single operand.
++
is also an arithmetic operator, as it applies to a number and performs an arithmetic operation (incrementing the number by one).

Mureinik
- 297,002
- 52
- 306
- 350
1
I think it won't be a mistake to call i++
both Arithmetic and Unary Operator.
However, Oracle doc here distinguishes and classifies ++
as Unary operator.

HoRn
- 1,458
- 5
- 20
- 25
-
I can't add anything to the answer. It's just a plain answer to the question asked plainly. Not to say much words, if we dive into [§15.14.2 – 15.15](https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.14.2) of Oracle Docs, indeed there is a separation between _Postfix_ Increment Operator ++ and Unary Operators. But as the question was about unary _or arithmetic_, my worring of it could be exessive. – HoRn Feb 01 '20 at 12:13
-
Then, at last, at the beginning of [§15.15](https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.15) it's said (in general?): "The operators +, -, ++, --, ~, ! ... are called the unary operators". The term "unary" then seems not so strict to argue about. Then i++ is also arithmetic because, as Mureinik said, simply, it performs an arithmetic operation – HoRn Feb 01 '20 at 12:14