2

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

12
  • Are those boolean variables static? Your initialization of the form Detail.isExchange = true; implies they are static (unless it's a typo). Commented Oct 9, 2015 at 5:44
  • What do the is* methods look like? Commented Oct 9, 2015 at 5:45
  • Are the booleans being set elsewhere? Commented Oct 9, 2015 at 5:45
  • Your code is. . . confusing. Detail.isExchange is apparently being set as a static variable in the Detail class. And then you are calling detail.isExchange() as a method? Perhaps show a bit more code here. Commented Oct 9, 2015 at 5:45
  • Add those methods isExchange(), etc here too. Commented Oct 9, 2015 at 5:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.