24

In Eclipse, when a variable is inspected and Eclipse is able to show its value, it does so by calling toString().

IntelliJ IDEA does not do it. Can it be told to?

Thanks.

ahmadPH
  • 135
  • 11
mark
  • 59,016
  • 79
  • 296
  • 580

4 Answers4

32

Settings | Debugger | Data Views:

Enable toString()

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • It is already enabled. But I see where is the problem - an alternative view for the Collection classes is enabled and my objects are indeed collections. I wish I could enjoy it both ways - if the object is collapsed - toString() is shown, if expanded - the alternative view, which is much better than the default collection view. – mark Jun 25 '12 at 13:21
  • but you need to click view object tree, and I want just to hover on the variable to see it , is that possible ? – Mohammed Subhi Sheikh Quroush Feb 03 '14 at 18:36
  • 2
    @MohammedSubhiSheikhQuroush did you ever figure out if this is possible? I too am looking for this automatic display, as I am used to what Eclipse does... – D-Klotz Jun 12 '14 at 20:30
  • 1
    I had it enabled, and then at some point just stopped getting the `toString()` outputs! The solution was simply to uncheck "Enable 'toString()' object view" -> Apply -> re-enable the same option -> apply and they're back! – flyingsilverfin Jul 21 '20 at 15:07
  • @flyingsilverfin reenabling is very helpful. I think for me it was caused by EAP idea. – amisiuryk Nov 26 '20 at 16:31
11

Using IDEA 13.1:

Preferences -> Debugger -> Data Type Renderers

  • +(add) new renderer, give it a name

  • On 'When rendering the node' select option 'Use following expression', type in 'toString()'.

This seems to give me Eclipse-like behaviour.

I'd paste a picture... but don't have enough points. :P

kva1966
  • 611
  • 6
  • 8
4

By default Intellij Idea does display the toString() of objects in debug view, unless you explicitly tell it not to in the dialog pointed by CrazyCoder above.

The problem that I have found is that for some crooked reason which only the folks at JetBrains understand, IntelliJ Idea (still as of version 13) will silently ignore the above setting and it will not invoke toString() on classes which do not override the toString() method. Even adding your class in the 'For classes from the list:' will not result in invocation of toString() unless your class explicitly overrides it. So, it appears that IntelliJ Idea will never ever invoke the default toString() method of class Object. I suppose it must be allergic to it.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
1

Right click the variable in the Debug window, and choose "view text". It will open a window showing "toString"

Yifan Peng
  • 97
  • 1
  • 2
  • Not sure why this was donevoted, was incredibly useful to me; stopped scala nodes (which secretly are collections) displaying in "stupid mode" – Richard Tingle Nov 23 '16 at 11:57