25

For example, having the following code:

// This is hidden from my eyes
String str = "abc";

// I can see this
System.out.println(str);

i'd like to point to str in the last line and see that it's type is indeed java.lang.String (not just String). Where can I find this information (I am sure Idea knows it, as it can show the object's members correctly)?

Ivan
  • 63,011
  • 101
  • 250
  • 382
  • 1
    This seems like plain old Java... why is it tagged as scala? – Pablo Fernandez Oct 19 '11 at 01:06
  • @pablo-fernandez, because I want this for Scala actually, but I believe this is done the same way with Java and there are more Java developers than Scala developers to answer the question. – Ivan Oct 19 '11 at 01:08

7 Answers7

32

Hover the mouse over the identifier with the ctrl key held down, and you will see a tooltip containing the full type name.

Ricky Clarkson
  • 2,909
  • 1
  • 19
  • 21
31

If you place the caret inside the variable you want to identify and press

CTRL + SHIFT + P

a small popup will show the type like so:

enter image description here

If you place the caret inside an expression, Idea will first ask what part of the expression you want to identify.

LCE
  • 874
  • 8
  • 15
1

The control-[hover over the identifier] thing works for Scala, but I don't use it very often. Most of the time I want to know the type of an expression, not just a symbol. [select an expression] followed by control-shift-P is the way to get that.

The command is called "expression type", so if those keyboard shortcuts aren't working for you, hit ⌘-shift-A and type in "expression type". It'll tell you your current shortcut for that command.

Closely related: I'll often tell Intellij to add type annotation to a binding. If your cursor is on fnord in a line like this:

var fnord = Monoid[Flurbish].sharky.shark.shark(!snowball)

Hit option-return, and one of the things you can do is add type annotation. If type annotation is already there, you can remove it, or if you've changed the type of the expression you can then have Intellij update the type annotation to the new one. (The command is called "Add type annotation to value definition")

James Moore
  • 8,636
  • 5
  • 71
  • 90
1

F1 key has worked for my Mac's community version: 2018.1.6

unknownerror
  • 2,235
  • 2
  • 25
  • 26
0

In CLion variant you can see a variable's definition in a pop-up with Command + Shift + I (Command uppercase letter 'i') ("Inspect" in my head to help me remember it).

Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70
0

In intelliJ you can directly jump to the type/class by pressing the keys CTRL+SHIFT and clicking with the mouse on the variable. That has the same effect as if you would ordinarily click with the mouse on the type along with key CTRL.

kladderradatsch
  • 596
  • 5
  • 18
0

[Ctrl]+[Alt]+T when the curser is inside the identifier. Also works for the return types of method invocations.

ziggystar
  • 28,410
  • 9
  • 72
  • 124