When I try to write a postfix/prefix in/decrement, followed by a post/prefix in/decrement, I get the following error: Invalid argument to operation ++/--.
But, according to JLS:
PostIncrementExpression:
PostfixExpression ++
and
PostfixExpression:
Primary
ExpressionName
PostIncrementExpression
PostDecrementExpression
so writing:
PostfixExpression ++ ++
should be possible... Any thoughts?
Note that the raw grammar lacks any semantics. It's just syntax, and not every syntactically valid program will generally be valid. For example, the requirement that variables have to be declared before usage is typically not covered by the grammar (you can, but it's cumbersome).
Postfix-increment yields an rvalue – and just as you cannot postfix-increment literals, you cannot postfix-increment the result of i++
.
Quoting from the JLS (3rd ed., page 486):
The result of the postfix increment expression is not a variable, but a value.
The error tells you the answer:
unexpected type
required: variable
found : value
(i++)++;
So, the i++ evaluates to a value while the operator requires a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With