Java赋值运算符

标签 java variable-assignment equality convention

以下引用摘自 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/

相关文章:

java - Java Web 应用程序上的打印服务

Delphi:TADoConnection 变量赋值的引用与副本

Python 切片按相反顺序赋值不起作用!为什么?

variable-assignment - Perl6 REPL打印行为

objective-c - 对于具有两个字符串和两个 BOOL 的对象,什么是好的散列?

perl - 比较两个数组哈希是否相等

java: log4j: jar 可执行文件的问题

java - 从不同值转换为枚举值

java - XML 解析太慢了!

if-statement - 如何在 if 语句中使用 (or)?