Organizing Imports

When referencing a class in your code for the first time, you can hover over the newly used class name and choose "Import 'Classname' (package name)" to have Eclipse quickly add the proper import statement.

In addition, the Organize imports command (Ctrl+Shift+O in Windows or Cmd+Shift+O on a Mac) causes Eclipse to automatically organize your imports. Eclipse removes unused imports and adds new ones for packages used but not already imported.

If there is any ambiguity in the name of a class during automatic import, such as with the Android Log class, Eclipse prompts you with the package to import.

Finally, you can configure Eclipse to automatically organize the imports each time you save a file. This can be set for the entire workspace or for an individual project. Configuring this for an individual project allows better flexibility when you're working on multiple projects and don't want to make changes to some code, even if they are an improvement. To configure this, perform the following steps:

1. Right-click the project and choose Properties.

2. Expand Java Editor and choose Save Actions.

3. Check Enable Project Specific Settings, Perform the Selected Actions on Save, and Organize Imports.

0 0

Post a comment