我收到以下代码行的编译错误“ Not an statement”:
parallel? stats[3]++ : stats[4]++;
不明白为什么?!
最佳答案
从this引用:
The following types of expressions can be made into a statement
by terminating the expression with a semicolon (;).
Assignment expressions
Any use of ++ or --
Method invocations
Object creation expressions
...
In addition to expression statements, there are two other kinds of
statements: declaration statements and control flow statements.
显然,您上面的代码行不属于上述任何类别。因此,编译器将引发错误。看最外面,而不是最里面。