奇怪的if-else行为:如果其他两个循环执行 [英] STRANGE IF-ELSE BEHAVIOR : IF-ELSE both loop executing
问题描述
我是用我的验证函数if-else语句。
我与所有的验证功能的验证类,然后我通过验证的类的对象来访问这些方法。
发生了什么事是控制既条件
i was using If-Else Statement in my validation function. I had a validation class with all the validation functions then i accessed these methods via the object of the Validation class . what happened is that the control was going inside both the conditions
if(some cond ..)
System.out.println("inside IF");
else
System.out.println("inside ELSE");
我也试过
if(some cond ..)
{
System.out.println("inside IF");
}
else
{
System.out.println("inside ELSE");
}
在这两种情况下的对照条件和印刷都行内外下去。
我无法解释这我自己,不管我给什么情况下,如果这不是一个语法错误,它应该只在任一循环的去,但不能同时
in both the cases the control was going inside both the conditions and printing both the lines. I could not explain this to my self , no matter what condition i give if this is not a syntax error it should only go in either of the loop but not both
有谁能够解释如何能不能可能两个IF和ELSE条件执行???
CAN ANYBODY EXPLAIN HOW CAN IT BE POSSIBLE THAT BOTH THE IF AND ELSE CONDITIONS BEING EXECUTED ???
我改变了我的项目,一段时间后,这是工作的罚款其他一些无关紧要的变化,但在那个时候,我无法解释我自己怎么可能
I made some other irrelevant changes in my project and after some time it was working fine , but at that time i could not explain my self how it was possible
顺便说一句,如果它很重要,我使用的是Android项目正在使用的Android因此编译器内该类
btw if it matters , i was using this class inside a android project thus android compiler was being used
推荐答案
您的意思是如果其他条件语句,不循环。
You mean if-else conditional statements, not loops.
这听起来像一个线程问题。你可能有一个线程,接着一条路径,而另一个调用同样的方法,去另一条路径上。这是你如何能得到显示两个字符串。
It sounds like a threading issue. You probably have a thread that goes on one route, while another one calls the same method and goes on the other path. This is how you can get both strings displayed.
为了调试,你可以打印 Thread.currentThread()
在每月底的System.out.println
电话。我敢肯定你会看到不同的发
目标地址。
In order to debug this, you could print Thread.currentThread()
at the end of each System.out.println
call. I'm sure you will see different Thread
object addresses.
这篇关于奇怪的if-else行为:如果其他两个循环执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!