java开发软件i,在Java中,为什么我不能编写i ++++或(i ++)++?

java开发软件i,在Java中,为什么我不能编写i ++++或(i ++)++?

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 thoughtsp>

解决方案

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.

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览93565 人正在系统学习中 相关资源:djs-economy:Discord.js机器人的经济软件包-其它代码类资源-CSDN…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月19日
下一篇 2021年1月19日

相关推荐