Why int[] a = new int[1] instead of just int a?

后端 未结 6 1388
无人及你
无人及你 2021-02-09 11:55

Is there some hidden meaning in this code which I don\'t see in java? How can it be useful?

int[] a = new int[1];

than just

int         


        
6条回答
  •  滥情空心
    2021-02-09 12:42

    One difference is that you can write a method that changes its int argument by changing arg[0]. This trick is used quite a bit in some of the code I've seen. It allows you to, for instance, return a boolean indicate success or failure and an int value that serves some other purpose. Without that trick, you'd have to return some sort of object containing the two values.

提交回复
热议问题