0

Is there any way, to log information about all data members of an object to the console, in a similar fashion to JS in chrome? Like how we get all information related to an object at a place in Chrome.

Code Hard
  • 43
  • 4

2 Answers2

1

Yes, in a fashion. Set a breakpoint (if you must, make a static method called breakpoint() which does nothing (e.g. System.currentTimeMillis(); is the only thing in it, you do need an actual executable statement even if it does nothing), set a breakpoint on it, and now you can call ThatThingie.breakpoint(). Start using 'debug' and not 'run' (this also gets you Hot Code Replace, and in general has no real downsides vs. Run), and then the debugger will stop on that line, and let you inspect every local variable and from there, every relevant field, in the debug perspective.

From there you can even do things like set a 'watch' and then continue the program, and you'll see that object change in real-time.

You can set a breakpoint by double-clicking in the margin (where the line-numbers are). A little green dot should appear.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
0

A solution might be to create a comprehensive toString() method in your class and then log it.

Couper
  • 414
  • 5
  • 13