简体   繁体   中英

JAVA return unexpected boolean result from method

Why the following method always return false for the below value. Do I confuse with somethings??

public boolean isTwoWay(Detail detail) {
    return (detail.isExchange && detail.isTwoWay && !detail.isIVR);
}

which data contain following

detail.isExchange =  true;
detail.isTwoWay = true;
detail.isIVR = false;

but it return false instead of true

The only way the method will return false is if one of your assumptions is wrong:

 detail.isExchange = true; detail.isTwoWat = true; detail.isIVR = false;

Rest assured, this kind of oversight happens to programmers all the time, including the best of us.

Put a breakpoint where you receive false instead of your expected true, and verify your assumptions.

I have tried with that and its print true always.

boolean isExchange =  true;
boolean isTwoWay = true;
boolean isIVR = false;

System.out.println(isExchange && isTwoWay && !isIVR);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM