Reputation: 29520
With eclipse i can easily transform the static invocation to
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 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 put the cursor on the method name (asList
) and press Ctrl-Shift-M
(Add Import
).
Now, for some refactoring reasons, i want to remove the static import and get back to the first code:
List<String> list = Arrays.asList("hello", "world");
Is there a shorcut quickly do that ?
Upvotes: 6
Views: 1910
Reputation: 519
Even if it's a former question:
You can do that using Eclipse Cleanup or Eclipse Save Action.
Warning: It looks like a bug to me but unchecking the options doesn't perform the opposite action.
Cleanup:
Puntual cleanup:
Save action:
Upvotes: 3
Reputation: 62864
You can't remove an (static
) import
statement with a shortcut, unless it's unused.
So, first comment out the statement:
//List<String> list = asList("hello", "world");
Then, activate the shortcut for Organizing Import Statements (Ctrl + Shift + O) and the unused import
statements will be automatically removed.
Finally, uncomment the line you commented first and refactor it so it compiles:
List<String> list = Arrays.asList("hello", "world");
Upvotes: 2