Using wildcards in imports may look cleaner as it reduces the number of lines in the import section and simplifies the code.
On the other hand,
it makes the code harder to maintain:
That is why it is better to import only the specific classes or modules you need.
Static imports are ignored by this rule. For example:
import static java.lang.Math.*;
will not raise an issue;
Depending on your IDE you can solve this issue almost automatically:
Look for Organize/Optimize imports
actions. These actions can also often be applied automatically on save.
Note: To make this work properly, you must adjust IDE settings to
use a very high allowed class count usage before using wildcards.
Resolving this issue manually will require a step-by-step approach:
import java.sql.*; // Noncompliant import java.util.*; // Noncompliant private Date date; // Date class exists in java.sql and java.util. Which one is this?
import java.sql.Date; import java.util.List; import java.util.ArrayList; private Date date;