David Wolever
David Wolever

Reputation: 154494

Use NetBeans to inspect live Java objects?

In Python, I'm used to being able to start a debugger at any point in the code, then poke around at live objects (call methods, that sort of thing). Is there any way, using NetBeans, to do this?

For example, I'd like to be able to break at the line foo = bar().baz().blamo() and run bar(), bar().baz() and bar().baz().blamo() to see what they do.

In Python, this is what I would do:

...
import pdb; pdb.set_trace()
foo = bar().baz().blamo()

Then it would give me a prompt where I could type things:

(pdb) bar()
... some objet ...
(pdb) bar() + 42
...

Upvotes: 0

Views: 6287

Answers (3)

Sai prateek
Sai prateek

Reputation: 11896

if you are running in debug mode and has set the debug pointer, then

(top left) debug --> Evaluate expression [Put your expression and run]

Upvotes: 0

TofuBeer
TofuBeer

Reputation: 61526

In the debugger use the "Watches" view. In there you can add things to "watch", such as variables or expressions.

So if you had a "foo" object you could do things like watch "foo.bar()" and have it call the method.

I am not aware of any Java debuggers that have a real "scratchpad" sort of thing, but there probably is one. The "Watches" is about as close as you can get in Netbeans that I have found.

Upvotes: 1

Michael Myers
Michael Myers

Reputation: 191915

First, set a breakpoint at that line of the code (by clicking in the left margin). Then click "Debug Main Project" (or "Debug single file" in the Debug menu).

Once you hit the breakpoint, you can use the tools in the Debug menu. In particular, "Evaluate Expression" seems to be what you're looking for.

Upvotes: 7

Related Questions