如何在 Eclipse java 编辑器中生成返回值类型和变量赋值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7094135/
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 generate return value type and variable assignment in Eclipse java editor?
提问by lisak
If I have a statement like this " EntitiesProvider.getEntities();
如果我有这样的声明“ EntitiesProvider.getEntities();
Any idea how to "generate" the assignment to variable of return Type ?
知道如何“生成”对返回类型变量的赋值吗?
so that this would be generated Map<String, Entity> hashMap =
这样就可以生成 Map<String, Entity> hashMap =
this is the result :
这是结果:
Map<String, Entity> hashMap = EntitiesProvider.getEntities();
It is similar to ctrl + 1 and Change type, if it returns different Type that you already have there.
它类似于 ctrl + 1 和 Change type,如果它返回您已经拥有的不同类型。
I find myself doing myself manually very often...
我发现自己经常手动操作...
回答by Art Licis
Ctrl+2, L
is one option, and the other is Alt+Shift+L
when the desired statement is selected. The popup will appear allowing to set variable name & few additional options (e.g., "Replace occurrences of the selected expression with references to the local variable").
Ctrl+2, L
是一种选择,另一种Alt+Shift+L
是选择所需语句时。弹出窗口将出现,允许设置变量名称和一些附加选项(例如,“用对局部变量的引用替换所选表达式的出现”)。
I prefer Alt+Shift+L
because it allows marking specific part of the line for variable extraction.
我更喜欢,Alt+Shift+L
因为它允许标记行的特定部分以进行变量提取。
.. and here's a simple example:
.. 这是一个简单的例子:
..
new FileInputStream(new File("test.txt"));
..
You can select the whole line to assign it to FileInputStream
variable, or you can 'extract' new File("test.txt")
, or even String expression "test.txt"
.
您可以选择整行以将其分配给FileInputStream
变量,或者您可以 'extract' new File("test.txt")
,甚至 String expression "test.txt"
。
P.S. Sometimes I wish it would be able to let me choose supertype from combo box in a pop-up, e.g. InputStream
in this specific example.
PS 有时我希望它能够让我从弹出窗口的组合框中选择超类型,例如InputStream
在这个特定示例中。
回答by Robin
CTRL=2,Lwill do what you are looking for.
CTRL=2,L会做你想要的。
回答by oliholz
What is wrong with Ctrl+2, L. With Taband ↓/↑?
Ctrl+ 有什么问题2,L。随着Tab和↓/ ↑?
回答by co_de_explorer
CTRL+2,L and ALT+CTRL+L can get the job done for you.
CTRL+2,L 和 ALT+CTRL+L 可以为您完成工作。
CTRL+2 is a short key to a quick assist tool which can perform
CTRL+2 是快速辅助工具的快捷键,可以执行
- assigning to a Field (F)
- assigning to a Local variable (L)
- extracting Method (M)
- Renaming in file (R)
- 分配给一个˚Field(F)
- 分配给一个大号OCAL变量(L)
- 提取中号ethod(M)
- R在文件中命名 (R)
you can press any key of these four as u need it.
您可以根据需要按这四个键中的任意键。