File: MixedArrayDimensions.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (33 lines) | stat: -rw-r--r-- 950 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
The Java language allows the `[]` to be placed after the declaration of a
variable or method:

```java
int foos[];
int getFoos() [] {
  return xs;
}
```

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

```java
int[] foos;
int[] getFoos() {
  return xs;
}
```

The
[Java Language Specification ยง8.4](https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-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][style].

[style]: https://google.github.io/styleguide/javaguide.html#s4.8.3.2-array-declarations