Can we assume default array values in Java? for example, assume that an int array is set to all zeros?

前端 未结 4 823
死守一世寂寞
死守一世寂寞 2020-11-29 19:31

In practice can I assume that all int arrays in Java will start out filled with zeros? for all machines in which the JVM runs?

Is this true for all types? char? bool

4条回答
  •  独厮守ぢ
    2020-11-29 20:17

    Yes. Primitive types in Java are always zero-initialized. References are also initialized to null.

提交回复
热议问题