Ko Ye
Ko Ye

Reputation: 77

In Java, is a++ a postfix operator or an unary operator?

In Java, is a++ a postfix operator or an unary operator? In the Operator Precedence from Oracle, it is separated. Reference

Upvotes: 0

Views: 277

Answers (1)

GizmoZa
GizmoZa

Reputation: 106

It’s both. It’s a unary operator because it works solely on one term. If it’s x++ then it’s a postfix operator as it’s incremented after using the variable’s value. A prefix unary operator is ++x where it’s incremented before being used. Prefix operators have a higher precedence, but they’re both unary operators

Upvotes: 4

Related Questions