Arturo Herrero Arturo Herrero - 2 months ago 18
Groovy Question

Static import statements which should never be after nonstatic imports

Codenarc is a framework that analyzes Groovy code for defects, bad practices, inconsistencies, style issues and more.

Is there a reason for this rule: MisorderedStaticImports Rule:

Checks for static import statements which should
never be after nonstatic imports.

Examples of violations:

import my.something.*
import static*

public class MyClass{}

I don't understand the motivation or implications for this rule.


As Marko Topolnik says, the order of the imports is not relevant to the meaning of a program.

I tried looking at the JLS for an explicit statement to that effect, but I couldn't find one. And the Java Tutorial doesn't mention import order either. However, the semantics of import are such that it makes no difference. If the imports result in any potential ambiguity due to import order, the JLS says it is a compilation error.

Therefore, this is just a stylistic convention. (Indeed, if you look at the rule, it even gives you the option of putting the static imports first!)