如何解决减少 java 中表达式中使用的条件运算符 (5) 的数量(最多允许 3 个)的声纳问题

How to fix sonar issues for Reduce the number of conditional operators (5) used in the expression (maximum allowed 3) in java

ObjectTest systemError = (ObjectTest ) o;
//New Code 
result &= Objects.equals(this.exp1, systemError.exp1);
result &= Objects.equals(this.exp2, systemError.exp2)  ;
result &= Objects.equals(this.exp3, systemError.exp3);
result &= Objects.equals(this.exp4, systemError.exp4);
result &= Objects.equals(this.exp5, systemError.exp5) ;
result &= Objects.equals(this.exp6, systemError.exp6);
return result;
//Old Code
return Objects.equals(this.exp, systemError.exp) &&
Objects.equals(this.exp1, systemError.exp1) &&
Objects.equals(this.exp2, systemError.exp2) &&
Objects.equals(this.exp3, systemError.exp3) &&
Objects.equals(this.exp4, systemError.exp4) &&
Objects.equals(this.exp5, systemError.exp5) &&
Objects.equals(this.exp6, systemError.exp6);

新代码是旧代码的解决方案吗?任何人都可以对此进行确认。

请注意,a &= ba = a & b 相同,出于实际目的,它与 a = a && b 具有相同的结果(除了性能与 a 的值无关) ,b 也将在 a & b 的情况下进行评估,而在 a && b 的情况下,如果 afalse,则 b 不会被处理)

在此基础上,如果您的新代码以 result = Objects.equals(this.exp, systemError.exp); 开始并以 return result;

结束,您的新代码确实可以解决旧代码

如果您在理解它时仍有任何问题,请随时告诉我,我会尝试进一步详细说明我的解释。