scala 如何在 IntelliJ Idea 中查看对象的完整类型名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7815446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to see an object's full type name in IntelliJ Idea?
提问by Ivan
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 strin 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)?
我想str在最后一行指出它的类型确实是java.lang.String(不仅仅是String)。我在哪里可以找到这些信息(我相信 Idea 知道它,因为它可以正确显示对象的成员)?
回答by Ricky Clarkson
Hover the mouse over the identifier with the ctrl key held down, and you will see a tooltip containing the full type name.
按住 ctrl 键将鼠标悬停在标识符上,您将看到一个包含完整类型名称的工具提示。
回答by lcersly
If you place the caret inside the variable you want to identify and press
如果将插入符号放在要识别的变量中并按
CTRL + SHIFT + P
CTRL + SHIFT + P
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.
如果您将插入符号放在表达式中,Idea 将首先询问您要识别表达式的哪一部分。
回答by James Moore
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.
control-[hover the identifier] 东西适用于 Scala,但我不经常使用它。大多数时候我想知道表达式的类型,而不仅仅是符号。[选择一个表达式] 后跟 control-shift-P 是获得它的方法。
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.
该命令称为“表达式类型”,因此如果这些键盘快捷键对您不起作用,请按 ?-shift-A 并输入“表达式类型”。它会告诉您该命令的当前快捷方式。
Closely related: I'll often tell Intellij to add type annotation to a binding. If your cursor is on fnordin a line like this:
密切相关:我会经常告诉 Intellij 向绑定添加类型注释。如果您的光标位于fnord 上,如下所示:
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")
点击选项返回,您可以做的一件事就是添加类型注释。如果类型注释已经存在,您可以将其删除,或者如果您更改了表达式的类型,则可以让 Intellij 将类型注释更新为新的类型。(该命令称为“向值定义添加类型注释”)
回答by unknownerror
F1key has worked for my Mac's community version: 2018.1.6
F1密钥适用于我的 Mac 社区版本:2018.1.6
回答by Andrew Mackenzie
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).
在 CLion 变体中,您可以使用 Command + Shift + I(Command 大写字母 'i')(在我的脑海中出现“Inspect”以帮助我记住它)在弹出窗口中看到变量的定义。
回答by ziggystar
[Ctrl]+[Alt]+T when the curser is inside the identifier. Also works for the return types of method invocations.
[Ctrl]+[Alt]+T 当光标在标识符内时。也适用于方法调用的返回类型。


