Return to site

Java coding: Pros of using a wild card with a Java import statement.

· java

―About name conflict, deal with it like that:
import java.sql.*;
import java.util.*;
import java.sql.Date;

―About performance:
No impact on performance as byte code is same.

―About software business practices:

  • C# always uses * (implicitly) as you can only using package name.
  • In Intellij Idea when you do "organize imports", it automatically replaces multiple imports of the same package with *.

―According to Robert C. Martin:
In Clean Code, Robert C. Martin actually recommends using them to avoid long import lists.
"Avoid Long Import Lists by Using Wildcards. If you use two or more classes from a package, then import the whole package with 'import package.*;'"

There are obviously cons related to wild card Java import. My point was to balance the point of view.