以下引用摘自 http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-137265.html
Do not use the assignment operator in a place where it can be easily confused with the equality operator. Example:
if (c++ = d++) { // AVOID! (Java disallows) ... }
should be written as
if ((c++ = d++) != 0) { ... }
我对这条线感到困惑
if ((c++ = d++) != 0) {
如有任何对此的澄清,我们将不胜感激。
最佳答案
在页面的最开始我可以看到 -
This page is not being actively maintained. Links within the documentation may not work and the information itself may no longer be valid. The last revision to this document was made on April 20, 1999
if ((c++ = d++) != 0) {
//logic
}
语法甚至无效(使用 Java6)。它给了我
The left-hand side of an assignment must be a variable
您需要将 C++ 分配给某个变量。
关于Java赋值运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28802519/