Horatiu Jeflea
Horatiu Jeflea

Reputation: 7404

How to step in a conditional if in eclipse debugging

I have the following structure :

if (obj.isSomethingable()){ 
// do something }

How can I enter the conditional if obj.isSomethingable() is false and I can't modify the boolean instance from obj ?

Upvotes: 1

Views: 476

Answers (4)

Horatiu Jeflea
Horatiu Jeflea

Reputation: 7404

Looks like the only way to do this is to modify the source code.

boolean bol = obj.isSomethingable();
if (bol) { ... }

After that you can change the boolean from Variables to true.

Upvotes: 0

jumping-jack
jumping-jack

Reputation: 237

Salut,

While in the Debug perspective, open the "variables" tab. you can select your object and change it's value. This will work for primitives or simple objects, but not on complex ones. I've tried the following:

return new MyObj() {
    public boolean isSomething() {
        return true;
    }
}; 

But eclipse won't allow you to use annonymous classes. You might try with a mock or something. Google mockito and see if it might work for you.

Tiberiu

Upvotes: 1

Ryan Stewart
Ryan Stewart

Reputation: 128899

Before executing the if, use the debugger to change the state of obj in such a way that isSomethingable() will return true.

Upvotes: 0

Grammin
Grammin

Reputation: 12205

You could use the eclipse's Display tab to execute the code is in //do something.

So if you have:

if(obj.isSomethingable())
{
  int var =5;
  System.out.println(var+8);
}

Then while at the if breakpoint in the display tab you can put in:

int var =5;
System.out.println(var+8);

Then highlight it all and click the magnifying glass to see what the output of that code would be.

Upvotes: 4

Related Questions