我创建了一个Enum磨损状态,然后将wearState作为两个变量的类型。但是当我尝试使用'||'将它们置于if条件时或“ &&”,它不起作用。 它说:“错误:二进制运算符'||'的错误操作数类型“
enum wearState {
WRIST_MOVE,
WRIST_IMMOBILE,
BELT_NECK_MOVE,
BELT_NECK_IMMOBILE,
OTHER_IMMOBILE_STATE;
}
enum chargingState {
YES,
NO,
}
wearState lastState;
wearState currentState;
chargingState lastStateCharging;
chargingState currentStateCharging;
if (((currentState = wearState.BELT_NECK_IMMOBILE) || (currentState = wearState.WRIST_IMMOBILE)) &&
(lastStateCharging = chargingState.NO)) {
/* .... */
}
答案 0 :(得分:0)
if (((currentState == wearState.BELT_NECK_IMMOBILE) || (currentState == wearState.WRIST_IMMOBILE)) &&
(lastStateCharging == chargingState.NO))
在比较两个变量是否请使用“ ==”时, =是赋值运算符。 它只能用于为变量赋值,例如
String name="Joe";
要与变量进行比较,我们应该使用比较运算符。 ==,<=,> =,!=,<,> 是比较运算符;