[英]Eclipse Java Debugger make if statement condition be true
I want to make a if statement become true only when I am debugging. 我只想在调试时使if语句变为true。
Example: 例:
if(giveMyNumber() == 3){
System.out.println("Is number 3");
}
public int giveMyNumber(){
return 1;
}
So i want to stop de debugger in if statement and simulate as (giveMyNumber() == 3) is true in order to go inside the if and print "Is number 3" 所以我想在if语句中停止调试器并模拟为(giveMyNumber()== 3)为true ,以便进入if并打印“ Is number 3”
You can use the Eclipse feature called Force Return to return the value 3
: 您可以使用称为“ 强制返回”的Eclipse功能来返回值
3
:
Forcing an early return from a non-void method requires an expression to be evaluated.
强制从非无效方法中尽早返回需要对表达式进行求值。 For example, if a method was going to return false you could return a value of true by selecting an expression in the Display View and invoking Force Return .
例如,如果某个方法要返回false,则可以通过在Display View中选择一个表达式并调用Force Return来返回true值。 In the following example,
elementCount
is not equal to zero, and would return false (see debug hover showing the value ofelementCount
).在下面的示例中,
elementCount
不等于零,并且将返回false(请参阅调试悬停,其中显示elementCount
的值)。Force Return Example http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/reference/views/shared/images/force-return-code.png
强制返回示例http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/reference/views/shared/images/force-return-code.png
From the Display View , we could enter the value we want returned, select it and use the Force Return command to force the method
isEmpty()
to return with that value (in the following example we will forceisEmpty()
to return with the valuetrue
).在Display View中 ,我们可以输入要返回的值,选择它,然后使用Force Return命令强制
isEmpty()
方法返回该值(在下面的示例中,我们将强制isEmpty()
返回该值true
)。Force Return Action in the Display View http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/reference/views/shared/images/force-return-action.png
在显示视图中强制返回操作http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.user/reference/views/shared/images/force-return-action.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.