简体   繁体   English

分配的左侧必须是变量

[英]Left-hand side of assignment must be a variable

I'm trying to call a boolean method in another class and Eclipse is reporting the above error on the second line in the following code: 我正在尝试在另一个类中调用布尔方法,并且Eclipse在以下代码的第二行报告了上述错误:

CCR ccrFlags = new CCR();
if (ccrFlags.cBit() = set)

The method being called from the class called "CCR" is: 从名为“ CCR”的类中调用的方法是:

public boolean cBit() {
    boolean set = false;
    return set;
}

I imagine I'm probably going about this in an idiotic way and would be grateful for any advice. 我想我可能会以一种愚蠢的方式来解决这个问题,感谢您的任何建议。 Thanks, Robert. 谢谢,罗伯特。

Comparison should use == (double-equal): 比较应该使用== (双等于):

CCR ccrFlags = new CCR();
if (ccrFlags.cBit() == set)

in an if, the condition has to be always true or false. 如果是,则条件必须始终为true或false。

your error is, that = only assigns the values, but it is not a logical operation which can be true or false. 您的错误是=仅分配值,但这不是逻辑运算,可以为true或false。

So you have to use == in conditions. 因此,您必须在条件中使用==。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM