Tuesday, September 11, 2012

Avoiding Name Collisions When Organizing Imports in Eclipse

Is there any way to get Eclipse to automatically give preference to a preferred import when organizing imports? Thankfully, the answer is yes.

For example, I'd like to be able to write:

List myList = new ArrayList();

hit Ctrl + Shift + O and have Eclipse add:

import java.util.List;

And not always ask me which List I want to import:

To tell Eclipse not to ever consider java.awt.List, for example, go to Preferences --> Java --> Appearance --> Type Filters menu. Click add and enter Types you do not want Eclipse to consider for automatic insertion of import statements.

Piece of Cake!!!