Skip to content

array-bracket-space

Javastyleno fixdefault: offjava/google

Reports an array creation in which the { of the initializer follows the ] right away (new int[]{1}).

The space between the brackets and the braces is the convention of the Java code style guides, and it separates the type from the initializer so that new int[] {1} reads as two parts.

To fix, put a space between ] and {.

Reported
class A {
Object a = new int[]{1};
Object b = new int[] {1};
Object c = new String[]{"a]{"};
Object d = new int[2];
int[] e = {1};
}
java:
lint:
rules:
array-bracket-space: warn # off (default), warn, error

Enabled by the presets: java/google.

Suppress one line with sudsy-disable-next-line array-bracket-space in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
checkstyle ArrayBracketNoWhitespace partial Only the { of an array creation right after the ].