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 Example1 {
  int[] nums; // ok since default format checks for Java style
  String strings[]; // violation, 'Array brackets at illegal position'

  char[] toCharArray() {
    return null;
  }

  byte getData()[] { // violation, 'Array brackets at illegal position'
    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 Example2 {
  int[] nums; // violation, 'Array brackets at illegal position'
  String strings[]; // OK as follows C style since 'javaStyle' set to false

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

  byte getData()[] { // violation, 'Array brackets at illegal position'
    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