OverloadMethodsDeclarationOrder

Since Checkstyle 5.8

Description

Checks that overloaded methods are grouped together. Overloaded methods have the same name but different signatures where the signature can differ by the number of input parameters or type of input parameters or both.

Examples

To configure the check:

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

Example of correct and incorrect grouping of overloaded methods:

class Example1 {
  void same(int i) {}
  // comments between overloaded methods are allowed.
  void same(String s) {}
  void same(String s, int i) {}
  void same(int i, String s) {}
  void notSame() {}
  interface notSame{}

  void otherSame(String s) {}
  void foo() {}
  // violation below, 'All overloaded methods should be placed next to each other'
  void otherSame(String s, int i) {}
}
        

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

Parent Module

TreeWalker