gpt4 book ai didi

java - Eclipse Java Debugger 使 if 语句条件为真

转载 作者:行者123 更新时间:2023-11-30 08:03:56 27 4
gpt4 key购买 nike

我只想在调试时使 if 语句变为真。

例子:

if(giveMyNumber() == 3){ 
System.out.println("Is number 3");
}

public int giveMyNumber(){
return 1;
}

所以我想在 if 语句中停止调试器并模拟为 (giveMyNumber() == 3)true 以便进入 if 并打印“是数字 3"

最佳答案

您可以使用名为 Force Return 的 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. In the following example, elementCount is not equal to zero, and would return false (see debug hover showing the value of elementCount).

Force Return Example
(source: eclipse.org)

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 force isEmpty() to return with the value true).

Force Return Action in the Display View
(source: eclipse.org)

关于java - Eclipse Java Debugger 使 if 语句条件为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36016553/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com