2

In Eclipse you can write a random expression in debug and it evaluates it. This is my code:

public static void main(String... args) {
     int x = 3;
*    System.out.print(x);
}

in the breakpoint I want to watch the expression

x

Then it shows 3.

But if I watch a custom expression like:

new java.util.Date()

which should return the current date, it displays

?

Cosmin Cosmin
  • 1,526
  • 1
  • 16
  • 34

2 Answers2

0

Does it work if you use the inspect option in debug mode?

Shay Shmeltzer
  • 3,693
  • 1
  • 13
  • 9
  • no, only if the expression was present in the code, or if I navigate inside the object via Reflexion, to see it's fields, not what its methods return. And this is what I want – Cosmin Cosmin Feb 06 '13 at 08:00
0

I think the problem is that it doesn't let you invoke constructors, at least not directly. However, you can be a bit devious and use reflection, i.e.

Class.forName("java.util.Date").newInstance()

as your watch expression gives you a new Date.

Possibly not quite on a par with what Eclipse lets you do, but still useful for some things.

Andy
  • 8,870
  • 1
  • 31
  • 39