[FindBugs分析记录]use of non-short-circuit logic

 

This code seems to be using non-short-circuit logic (e.g., & or |) rather than short-circuit logic (&& or ||). In addition, it seem possible that, depending on the value of the left hand side, you might not want to evaluate the right hand side (because it would have side effects, could cause an exception or could be expensive.

Non-short-circuit logic causes both sides of the expression to be evaluated even when the result can be inferred from knowing the left-hand side. This can be less efficient and can result in errors if the left-hand side guards cases when evaluating the right-hand side can generate an error.

大致意思是:

  这段代用的是非简洁逻辑(例如,&或|),而不是简洁逻辑(&&或| |)。它似乎可能的是,只想根据左边的值,而不用不希望评估右边值(因为这会产生副作用,可能会导致异常或可能是昂贵的代价),非短路逻辑必须通过两侧的值来评估最终结果,这可能是低效率的,并且可能导致错误(左边表达式是正确的,右边表达式可能会是一个错误)。

所以这里的建议是:为了防止错误发生,建议使用简洁逻辑&&或||。

PS:

  &称为逻辑与,只有两个操作数都是true,结果才是true。&&称为简洁与或者短路与,也是只有两个操作数都是true,结果才是true。但是如果左边操作数为false,就不计算右边的表达式,直接得出false。类似于短路了右边。

  |称为逻辑或,只有两个操作数都是false,结果才是false。||称为简洁或或者短路或,也是只有两个操作数都是false,结果才是false。但是如果左边操作数为true,就不计算右边的表达式,直接得出true。类似于短路了右边。

转载于:https://my.oschina.net/lianghan/blog/345793

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值