Eclipse : transform static method invocation to a static import

女生的网名这么多〃 提交于 2019-12-03 04:04:45

问题


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".


回答1:


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.



来源:https://stackoverflow.com/questions/15567332/eclipse-transform-static-method-invocation-to-a-static-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!