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

后端 未结 5 2123
终归单人心
终归单人心 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 03:57

    This is an example that shows you when the [] position makes a difference.

    String[] arr, arr2[];
    

    The arr is an array of String whereas the arr2 is an array of arrays of String.

    It can as you see be beneficial if you want to declare different arrays on the same line.

    And in your example it could have been another var2 declared on the same line:

    private String[][] var[], var2;
    

提交回复
热议问题