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

后端 未结 6 1386
无人及你
无人及你 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:24

    All arrays in java are objects. when declaring: int x = 5; you're declaring a primitive type.

    When declaring int[] x = new int[]; you're creating an object with type int[].

    So int[] is actually a class.

提交回复
热议问题