![](/img/trans.png)
[英]Reduce the number of conditional operators (4) used in the expression (maximum allowed 3) in SONAR
[英]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 &= b
与a = a & b
相同,出于实际目的,其结果与a = a && b
相同(除了与a
的值无关的性能外, b
也将在 a 的情况下a & b
评估a & b
而在a && b
的情况下,如果a
为false
则不处理b
)
在此基础上,如果您以result = Objects.equals(this.exp, systemError.exp);
开始您的新代码,那么您的新代码确实可以成为旧代码的解决方案。 并以return result;
如果您在理解它时仍有任何问题,请随时告诉我,我将尝试进一步详细说明我的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.