Eclipse:将静态方法调用转换为静态导入 [英] Eclipse : transform static method invocation to a static import
问题描述
Arrays.asList
): import java.util.Arrays;
import java.util.List;
public class StaticImport {
public static void main(String [] args){
列表< String> list = Arrays.asList(hello,world);
System.out.println(list);
}
}
使用静态导入
:
import static java.util.Arrays.asList;
import java.util.List;
public class StaticImport {
public static void main(String [] args){
列表< String> list = asList(hello,world);
System.out.println(list);
}
}
我知道我可以使用这个配置代码完成窗口»首选项»Java»编辑»内容辅助»收藏夹
如这个答案。
我的问题是关于转换现有的静态方法调用。理想情况下,我不需要配置最喜爱的导入。
将光标放在方法名称( asList
),然后按 Ctrl-Shift-M
。
这是添加导入命令的默认键盘快捷方式。您还可以在源菜单上找到该命令。
Is there a way to transform automatically this static method invocation (Arrays.asList
):
import java.util.Arrays;
import java.util.List;
public class StaticImport {
public static void main(String[] args) {
List<String> list = Arrays.asList("hello", "world");
System.out.println(list);
}
}
to this invocation using a static import
:
import static java.util.Arrays.asList;
import java.util.List;
public class StaticImport {
public static void main(String[] args) {
List<String> list = asList("hello", "world");
System.out.println(list);
}
}
I know that i can configure the code completion using this Window » Preferences » Java » Editor » Content Assist » Favorites
as described in this answer.
My question is about transforming an existing static method invocation. Ideally, i would like do not have to configure a "favorite import".
Put the cursor on the method name (asList
) and press Ctrl-Shift-M
.
This is the default keyboard shortcut for the 'Add Import' command. You can also find the command on the 'Source' menu.
这篇关于Eclipse:将静态方法调用转换为静态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!