Eclipse:将静态方法调用转换为静态导入 [英] Eclipse : transform static method invocation to a static import

查看:189
本文介绍了Eclipse:将静态方法调用转换为静态导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法自动转换这个静态方法调用( 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 » Favoritesas 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆