Left-hand side of assignment must be a variable

我的梦境 提交于 2019-12-25 04:06:26

问题


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:

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

The method being called from the class called "CCR" is:

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.


回答1:


Comparison should use == (double-equal):

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



回答2:


in an if, the condition has to be always true or false.

your error is, that = only assigns the values, but it is not a logical operation which can be true or false.

So you have to use == in conditions.



来源:https://stackoverflow.com/questions/11243805/left-hand-side-of-assignment-must-be-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!