Difference in Array initialization

后端 未结 5 1087
故里飘歌
故里飘歌 2021-01-20 23:40

While looking over a source file, i saw two ways of array initialization. I wonder is there a difference between

int[] value = new int[0];

and<

5条回答
  •  自闭症患者
    2021-01-21 00:42

    There is no difference, although in the second case you have redundant [].

    Personally I prefer to use int[] value_next = {} to create an empty array.

    In my opinion, int[] value = new int[0]; can, on rapid reading, look like you're creating an array with one element in it with initial value of 0. During a 3am debugging session I really appreciate clarity.

提交回复
热议问题