Evaluating an expression in IntelliJ


What is the best way in IntelliJ to find out the value of an expression?
For example, in the attached image, I’ve highlighted an expression. I’d like to see its printed value, i.e., the value it would be at runtime. Is this possible?


Having just figured this out myself yesterday: at least on the Mac, with the default keybindings, it’s ctrl-shift-P.


Nope, sadly that doesn’t work for me.


Well, I think if you go to Preferences -> Keymap -> Plug-ins -> Scala -> Type Info, it ought to be listed there…


Alternatively, you can invoke any action by pressing Ctrl+Shift+A (Cmd+Shift+A on macOS) and typing in its name, meaning the suggested previously “Type Info”. It’s not as convenient as a shortcut, but should do in cases when there is no key binding for an action.

On the other hand, I encountered several cases when Type Info didn’t work for expressions. That might be a bug and should probably be reported as such.


HI azolotko , is “Type Info” what I really want? I’d rather see the value than the type. I’ve seen this done with worksheets, but I don’t really understand the relation between worksheets and source code files.


Oh, I see – sorry, I had misread what you were looking for. Obviously, it’s not possible to show the value in the general case, since many expressions are parameterized. It would theoretically be possible to do so for an expression composed solely of literals, but I’m not sure I’ve seen that feature in any IDE…


Sorry, I followed jducoeur’s answer and didn’t even bother to read the initial post :slight_smile:

I think the one way to evaluate an expression is to start “Scala Console” (Command+Shift+D on macOS) and then “Send Selection to Scala Console” (Control-Shift-X). Another one is to evaluate it in the debugger.