Why java allows private String[][] var[]

后端 未结 5 2141
终归单人心
终归单人心 2021-01-20 03:21
private String[][] var[]

This code compiles. But shouldn\'t they make the array on type or variable?

5条回答
  •  半阙折子戏
    2021-01-20 04:03

    According to the JLS 10.2 in the section about Array's:

    The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.

    For example:

    byte[] rowvector, colvector, matrix[]; This declaration is equivalent to:

    byte rowvector[], colvector[], matrix[][];

    (Emphasis mine)

    Note especially the last example where it says byte[] matrix[] is equivalent to byte matrix[][].

    So no, it is not a bug, simply a design choice.

提交回复
热议问题