Pattern: Use of star import
Issue: -
Importing all classes from a package or static members from a class leads to tight coupling between packages or classes and might lead to problems when a new version of a library introduces name clashes.
In addition, by explicitly listing all imports you can tell at a glance which class you meant to use, which simply makes reading the code that much easier. Also, modern IDEs should address possible maintenance issues related to explicit imports (e.g. removing or renaming a class).
An example how to configure the check so that star imports from packages java.io
and java.net
as well as static members from class from java.lang.Math
are allowed:
<module name="AvoidStarImport">
<property name="excludes" value="java.io,java.net,java.lang.Math"/>
<property name="allowClassImports" value="false"/>
<property name="allowStaticMemberImports" value="false"/>
</module>