Embracing the Messiness in Search of Epic Solutions

IntelliJ: Preventing Wildcard Imports




I have been getting the following PMD warning that I can’t seem to suppress with PMD’s @SuppressWarnings

RequestServiceImpl.java:1, UnnecessaryFullyQualifiedName, Priority: Normal

Unnecessary use of fully qualified name 'com.choonchernlim.epicapp.service.impl'
due to existing import 'com.choonchernlim.epicapp.service.*'.

The reason I’m getting this warning is because IntelliJ will automatically replace all single imports from the same package with a wildcard ‘*’ when the class count hits a certain limit.

By using wildcard imports, it also becomes difficult for my peers to understand where the classes are coming from.


To fix this permanently in IntelliJ:-

  1. Go to Preferences…Code StyleJava.
  2. Go to Imports tab.
  3. Check Use single class import
  4. Set a ridiculous high number on Class count to use import with ‘*’ and Names count to use static import with ‘*’ because these fields cannot be empty. In my case, I set 100 for each field.
  5. Select OK.

Finally, perform an Optimize Imports… on that Java file in question.


Leave a Reply