ModifierOrder

Since Checkstyle 3.0

Description

Checks that the order of modifiers conforms to the suggestions in the Java Language specification, § 8.1.1, 8.3.1, 8.4.3 and 9.4. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. default
  6. static
  7. sealed
  8. non-sealed
  9. final
  10. transient
  11. volatile
  12. synchronized
  13. native
  14. strictfp

In additional, modifiers are checked to ensure all annotations are declared before all other modifiers.

Rationale: Code is easier to read if everybody follows a standard.

ATTENTION: We skip type annotations from validation.

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="ModifierOrder"/>
  </module>
</module>
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.modifier

Parent Module

TreeWalker