C-style array declarations should not be used


The problem

The Java language allows the [] to be placed after the declaration of a variable or method:

int foos[];
int getFoos() [] {
  return xs;

The example above is equivalent to the following, strongly preferred, form:

int[] foos;
int[] getFoos() {
  return xs;

The Java Language Specification ยง8.4 notes:

The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.

Placing the square brackets immediately after the type is required by the Google Java Style Guide.


Suppress false positives by adding the suppression annotation @SuppressWarnings("MixedArrayDimensions") to the enclosing element.