逻辑或条件未按预期工作
在我的 Decision 类中,我有 3 个条件语句,如下所示:
GeneralCondition 类包含提示用户(用户)。
class Decision extends GeneralCondition{
private boolean hasChildrens(User user){
return user.getHaveChilds();
}
private boolean hasSpouse(User user){
return user.getHaveSpouse();
}
private boolean newUser(User user){
return user.isNewUser();
}
boolean interruptUser(User user){
boolean hasChildrens=boolean hasChildrens(User user);
boolean hasSpouse= boolean hasSpouse(User user);
boolean newUser= newUser(User user);
return hasChildrens||hasSpouse||newUser;
}
}
//下面是调用interruptUser()的类:
class UserCondition extends GeneralCondition{
GeneralCondition gcon=new GeneralCondition();
if(gcon.interruptUser(user)){
//重定向到条件 PopUp Flow;
}
else
{
//重定向到主页;
}
}
interruptUser(user)
被其他对象调用。当我每次都返回 False 时使用上述所有 3 个条件,即使它是 true ;当我只使用 2 个条件时,它会按预期工作。请提出可能是什么原因。
In my Decision class, I have 3 conditional statement like below:
GeneralCondition class contains promptUser(user).
class Decision extends GeneralCondition{
private boolean hasChildrens(User user){
return user.getHaveChilds();
}
private boolean hasSpouse(User user){
return user.getHaveSpouse();
}
private boolean newUser(User user){
return user.isNewUser();
}
boolean interruptUser(User user){
boolean hasChildrens=boolean hasChildrens(User user);
boolean hasSpouse= boolean hasSpouse(User user);
boolean newUser= newUser(User user);
return hasChildrens||hasSpouse||newUser;
}
}
//Below is the class caalling interruptUser():
class UserCondition extends GeneralCondition{
GeneralCondition gcon=new GeneralCondition();
if(gcon.interruptUser(user)){
//redirect to condition PopUp Flow;
}
else
{
//redirect to Home Page;
}
}
interruptUser(user)
is called by other object. When I use all 3 condition as above every time it returns False, even if it is true; and when I use only 2 condition it works as expected. Please suggest what could be reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在尝试使用 Java 编程语言测试该程序。问题是您的代码不正确,并且很可能永远无法编译。
Seems like you are trying to test this program with the Java programming language. The problem is that your code is not correct and will never compile, most likely.
试试这个。该函数需要传入一个 User 对象,然后将该对象传递给每个需要它的测试函数。
Try this. The function needs to have a User object passed in, and then pass that object to each of the test functions that needs it.