[英]Automatic variable expansion in IntelliJ
I'm working at a Java shop this summer and I'm coming from a C# job. 我今年夏天在一家Java商店工作,我来自C#工作。 I got super used to just typing
var x = randomMethod();
我已经习惯了输入
var x = randomMethod();
In IntelliJ is there anyway to type something like this and then have it automatically expanded to the correct return type after hitting enter. 在IntelliJ中,无论如何都要键入这样的东西,然后在输入后自动扩展到正确的返回类型。 So something like
var x = newStringList();
所以像
var x = newStringList();
becomes List<String> x = newStringList();
成为
List<String> x = newStringList();
Rumel, welcome to the java world, and this one is easy... Rumel,欢迎来到java世界,这个很容易......
First, type the method name (start typing it and use Ctrl + Space to autocomplete, if you like...) 首先,键入方法名称(开始键入它并使用Ctrl + Space自动完成,如果您愿意......)
newStringList()
With your cursor still on the method, or the parenthesis, now hit Ctrl + Alt + V (refactor: Introduce Variable ) and type the variable name you want (instead of the default, which is strings
). 当光标仍在方法或括号上时,现在按Ctrl + Alt + V (重构: 引入变量 )并键入所需的变量名称(而不是默认值,即
strings
)。
List<String> strings = newStringList();
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.