如何在 IntelliJ Idea 中查看对象的完整类型名称?
例如,有以下代码:
// This is hidden from my eyes
String str = "abc";
// I can see this
System.out.println(str);
我想指向最后一行中的 str
并查看它的类型确实是 java.lang.String
(不仅仅是 <代码>字符串)。我在哪里可以找到这些信息(我确信 Idea 知道它,因为它可以正确显示对象的成员)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
按住 ctrl 键将鼠标悬停在标识符上,您将看到包含完整类型名称的工具提示。
Hover the mouse over the identifier with the ctrl key held down, and you will see a tooltip containing the full type name.
如果将插入符号放在要识别的变量内,然后按
一个小弹出窗口将显示如下类型:
如果您将插入符号放入表达式中,Idea 将首先询问您要识别表达式的哪一部分。
If you place the caret inside the variable you want to identify and press
a small popup will show the type like so:
If you place the caret inside an expression, Idea will first ask what part of the expression you want to identify.
control-[将鼠标悬停在标识符上] 适用于 Scala,但我不经常使用它。大多数时候我想知道表达式的类型,而不仅仅是符号。 [选择一个表达式] 后跟 control-shift-P 是获得该结果的方法。
该命令称为“表达式类型”,因此如果这些键盘快捷键不适合您,请按 ⌘-shift-A 并输入“表达式类型”。它会告诉您该命令当前的快捷方式。
密切相关:我经常告诉 Intellij 将类型注释添加到绑定中。如果您的光标位于 fnord 上,如下所示:
点击 option-return,您可以做的事情之一就是添加类型注释。如果类型注释已经存在,您可以将其删除,或者如果您更改了表达式的类型,则可以让 Intellij 将类型注释更新为新类型注释。 (该命令称为“将类型注释添加到值定义”)
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:
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")
F1
键适用于我的 Mac 社区版本:2018.1.6F1
key has worked for my Mac's community version: 2018.1.6当光标位于标识符内部时,[Ctrl]+[Alt]+T。也适用于方法调用的返回类型。
[Ctrl]+[Alt]+T when the curser is inside the identifier. Also works for the return types of method invocations.
在 CLion 变体中,您可以使用 Command + Shift + I(命令大写字母“i”)在弹出窗口中看到变量的定义(在我的脑海中“检查”以帮助我记住它)。
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).
在 intelliJ 中,您可以通过按 CTRL+SHIFT 键并在变量上单击鼠标来直接跳转到类型/类。这与您通常用鼠标并按 CTRL 键在文字上单击的效果相同。
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.