Is there a way to disable short circuit evaluation in Java?

Say I have this Code:

boolean ret = a() && b() && c() && d() && e();

E () is called only if all other calls a () – D () return true Is it possible that there are some compiler or JVM options to disable short circuit evaluation, so e () will always be called regardless of the results of other functions?

Basically, I'm working on the huge system of UAT. I need to test e (), but it's very painful to set the environment and scenario to ensure that all a (), B (), etc. return true

Editor: OK, I guess and is used instead of logic, which can provide some solutions, but ideally, I'm looking for a solution that doesn't need any changes in the source code For formal and technical reasons (as I said, the system is very large, and we promote and deploy the code between staging areas and get the sign off process) This is just for testing, and the production version needs to enable lazy evaluation (i.e. using&&&

Autopsy report:

>The "correct" answer is: No, No. > "Useful" answer: you can change & & to & > "what did I do" answer: debug the system remotely, put the breakpoint on the expression, and tell eclipse to run e ()-_-

Solution

There are no compiler or JVM options for changing Boolean expression evaluation semantics

If you cannot modify the source, possible (though not guaranteed) options include:

>Creatively recreate the conditions you test through careful design and set preconditions. > Use mock objects Crack compiler > crack JVM. > Convert bytecode

Sorry, these are much more difficult than compiler / JVM options or modifying the source code In addition, the last three options (and the requested compiler / JVM option or modify source) violate the correct test protocol and do not modify the tested content

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>