Left-hand side of assignment must be a variable

2019-09-06 21:16发布

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.

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-06 22:14

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.

查看更多
狗以群分
3楼-- · 2019-09-06 22:16

Comparison should use == (double-equal):

CCR ccrFlags = new CCR();
if (ccrFlags.cBit() == set)
查看更多
登录 后发表回答