Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Eclipse auto-complete import statement without adding wildcard?

Tags:

java

eclipse

When I'm typing import statements in Eclipse a list of auto-complete options are given, but when I select one, it adds a wildcard for the whole package, e.g. org.apache.*, but I want to auto-complete the just the package name and continue typing a sub-package or class, e.g. org.apache.log4j.Logger

like image 547
pnewhook Avatar asked Jan 29 '16 16:01

pnewhook


People also ask

Why is it better to avoid * in import statements in Java?

Wildcard imports tell java compiler to search for class names in the given package. Hence, using wild card imports, the compile-time performance may lower a bit.

Should we use wildcard imports?

In fact, the book recommends using wildcard imports when using multiple classes from the same source. In other words, when we import two or more classes imported from a package, it's better to import the whole package.

Does Eclipse auto import?

In above situation, Eclipse comes with a nice feature called “Organize Imports” to imports all the classes that are used, automatically. A copied source code without imports.

How do I disable wildcard import in IntelliJ?

Disable wildcard importsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.


2 Answers

Eclipse has a setting for the number of imports needed in order to stop listing the classes one by one and use the package.* syntax instead.

You can change that setting by going to Window>Preferences>Java>Code Style>Organize Imports.

Put a large number into the edit boxes at the bottom.

like image 91
f1sh Avatar answered Dec 05 '22 04:12

f1sh


Rather than typing individual import statements by hand, consider just typing the names of classes where you need them, then using Content Assist (Ctrl+Space or Command+Space on OS X) and let Eclipse auto-insert the import statement for you automatically. It won't use a wildcard import unless you've configured it to do that at a certain threshold (see @f1sh's answer).

like image 39
E-Riz Avatar answered Dec 05 '22 03:12

E-Riz