ArrayTypeStyle

Since Checkstyle 3.1

Description

Checks the style of array type definitions. Some like Java style: public static void main(String[] args) and some like C style: public static void main(String args[]).

By default, the Check enforces Java style.

This check strictly enforces only Java style for method return types regardless of the value for 'javaStyle'. For example, byte[] getData(). This is because C doesn't compile methods with array declarations on the name.

Properties

name description type default value since
javaStyle Control whether to enforce Java style (true) or C style (false). boolean true 3.1

Examples

To configure the check to enforce Java style:

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

Example:

public class MyClass {
  int[] nums; // OK
  String strings[]; // violation

  char[] toCharArray() { // OK
    return null;
  }

  byte getData()[] { // violation
    return null;
  }
}
        

To configure the check to enforce C style:

<module name="Checker">
  <module name="TreeWalker">
    <module name="ArrayTypeStyle">
      <property name="javaStyle" value="false"/>
    </module>
  </module>
</module>
        

Example:

public class MyClass {
  int[] nums; // violation
  String strings[]; // OK

  char[] toCharArray() { // OK
    return null;
  }

  byte getData()[] { // violation
    return null;
  }
}
        

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

Parent Module

TreeWalker