简体   繁体   English

如何解决减少 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);

Does the New code is the solution for Old code?Can any one shed some confirmation on this.新代码是旧代码的解决方案吗?任何人都可以对此进行确认。

Note that a &= b is same as a = a & b which will have the same result as a = a && b for practical purposes (except for performance as irrespective of the value of a , b will also be evaluated in case of a & b while in case of a && b , b is not processed if a is false )请注意, a &= ba = a & b相同,出于实际目的,其结果与a = a && b相同(除了与a的值无关的性能外, b也将在 a 的情况下a & b评估a & b而在a && b的情况下,如果afalse则不处理b

On this basis, your new code can be indeed the solution for the old code provided you start your new code with result = Objects.equals(this.exp, systemError.exp);在此基础上,如果您以result = Objects.equals(this.exp, systemError.exp);开始您的新代码,那么您的新代码确实可以成为旧代码的解决方案。 and end it with return result;并以return result;

Feel free to let me know if you still have any problem understanding it and I will try to elaborate my explanation a bit further.如果您在理解它时仍有任何问题,请随时告诉我,我将尝试进一步详细说明我的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 减少 SONAR 中表达式中使用的条件运算符 (4) 的数量(最多允许 3 个) - Reduce the number of conditional operators (4) used in the expression (maximum allowed 3) in SONAR 减少表达式中使用的条件运算符(4)的数量(允许的最大值3) - Reduce number of conditional operators(4) used in the expression (maximum allowed 3) java:S1067 - 减少表达式中使用的条件运算符 (5) 的数量(最多允许 3 个) - java:S1067 - Reduce the number of conditional operators (5) used in the expression (maximum allowed 3) 减少条件运算符的数量 - Reduce number of conditional operators 减少条件运算符的数量 - Reduce the number of conditional operators java表达式太复杂,减少了conditionl运算符的数量 - java Expression too complex reduce the number of conditionl operators 如何设置电话号码的正则表达式中允许的最小和最大位数 - How to set the minimum and maximum number of digit allowed in a regex expression for telephone number Java 带声纳:降低方法复杂度 - Java with sonar: reduce complexity of method 如何找到小于N的最大数M,其中Java中不允许存在某些特定数字 - how to find maximum number M less than N in which some specific digit is not allowed to exist in Java 如何在 Java 中评估带有逻辑运算符的表达式? - How are expression with logical operators evaluated in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM