It’s a big hassle to manually organise package import statements so it’s important to know what tools are available so your IDE can handle imports as quickly and quietly as possible.
Adding import statements for missing references and removing unused imports can take ages and the list of imports can get very long and hard to manage. As an example, the import statements below can consist of static/normal imports and wildcard/class imports:
// The list of imports can get really long... import static org.junit.Assert.assertEquals; // Static imports import java.util.List; import java.util.ArrayList; import org.apache.commons.lang.*; // Wildcard; unused so should be removed ... public class MyTest { @Test public void testSomething() throws Exception { List<String> messages = new ArrayList<String>(); assertEquals(1, 1); } }
To make life easier, Eclipse has a heap of features that automatically manage import statements, including organising them when you save or when you press a keyboard shortcut. It can even deal with static imports. This tip covers some of these features, starting with the absolute essentials that save loads of time and moving on to more optional features that will depend on your environment and tastes.