Skip to content

Files

Latest commit

 

History

History
27 lines (18 loc) · 1.38 KB

AvoidStarImport.md

File metadata and controls

27 lines (18 loc) · 1.38 KB

Pattern: Use of star import

Issue: -

Description

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).

Examples

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>

Further Reading