Reputation: 23
I want to make a if statement become true only when I am debugging.
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"
Upvotes: 2
Views: 5041
Reputation: 159106
You can use the Eclipse feature called Force Return to return the value 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 ofelementCount
).
(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 forceisEmpty()
to return with the valuetrue
).
(source: eclipse.org)
Upvotes: 3
Reputation: 2063
You can use Conditional Breakpoint. Add a breakpoint and select Breakpoint Properties...
Take a look in image bellow.
Select you breakpoint and write the condition, in your case:
giveMyNumber() == 3
Upvotes: 0