Cyt*_*max 3 java if-statement conditional-statements
在我的JAVA程序中,我有这个"if"条件:
if( (!pccoNettNoAff && !transOPCVM && !garantie)
&& ( (pccoCourant == null)
|| ( (pccoCourant != null && rBale.getPcco() != null)
&& ( (pccoCourant.getId() != rBale.getPcco().getId())
|| ( pccoCourant.getId() == rBale.getPcco().getId()
&& tauxCourant!=null && rBale.getTauxCcf()!=null
&& rBale.getPartenaire()==null
&& rBale.getTauxCcf()!=tauxCourant
)
)
)
)
)
{
Run Code Online (Sandbox Code Playgroud)
我们可以通过以下方式将其翻译为:
图例:T = true,F = False:它们是每次测试的结果
((T)AND((F)OR((T)AND((F)OR(F)))))
所以我的最终结果显然是假的(Eclipse调试模式找到相同的结果)但是我的程序无论如何都要通过这个"if".
我真的不知道为什么会发生这种情况,也许在"if"条件下存在某种限制?
如果有人有任何想法,请帮助我:)
问候,
Cytemax
And*_*yle 13
我知道它为什么会发生 - 因为这对于在线条件来说太复杂了.
重构代码到一个方法(或可能的几个),因此你可以把东西多条线路上,增加临时变量等,它将成为更加清晰既它是什么意思做的,为什么它没有这样做.类似于以下内容:
private boolean shouldBeActedOn(PCCO pccoCourant) {
if (pccoCourant != null) {
return true;
}
final PCCO balePcco = rBale.getPcco()
if (balePcco != null) {
// etc.
}
...
}
// Then later, where your current block is:
if (shouldBeActedOn(pccoCourant, otherArgs)) {
...
}
Run Code Online (Sandbox Code Playgroud)
请放心,Java的if陈述正常.
一个想法:在一个声明中没有这么多荒谬的条件.
你几乎没有机会在没有简化的情况下弄清楚这里发生了什么.将子表达式提取到单独的局部变量中,然后使if条件只组合这些局部变量.
你有这样多的工作发生了什么事情的更好的机会.你有可能在某个地方错误地解释了调试器......