Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse/Java - is it harmful to import java.(namespace).*?

Why does Eclipse take a fine grained approach when importing types? In C# I'm used to things like "using System.Windows.Controls" and being done with it, but Eclipse prefers to import each widget I reference individually (using the Ctrl+Shift+O shortcut). Is there any harm to importing an entire namespace if I know I'll need multiple types in it?

like image 257
James Cadd Avatar asked Dec 31 '09 01:12

James Cadd


People also ask

Do imports slow down java?

Imports can have an effect on compilation time, but not on loading time or running time. Basically, if you import classes that you don't need (typically by using wildcard imports when explicit imports would do), then you can slow the compiler a bit.

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.

Why is it important that java allows you to partition the namespace?

One of the important functions of packages is to partition the Java namespace and prevent name collisions between classes. It is only their package names that keep the java.

What is java namespace?

Java packages are namespaces. They allow programmers to create small private areas in which to declare classes. The names of those classes will not collide with identically named classes in different packages.


1 Answers

Eclipse has a great setting called the "Organize Imports" in the Window -> Preferences dialog that lets you say when N classes are used from a package, do a wildcard import. I use it at N=2 or 3 usually.

like image 160
Kristopher Ives Avatar answered Oct 06 '22 11:10

Kristopher Ives