Why and how does this strange method return type compile?

noobcoder :

The following method has a return type of int[][]. Note how one of the []'s are on the right hand side of the ()'s.

Why does this work and what is this behavior called?

int[] numbers () [] {
    return null;
}
JB Nizet :

From the JLS

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=306984&siteId=1