Why doesn't Java initialize Array Objects?

后端 未结 2 1966
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 02:43

If one runs the following code in java:

public class Testing {

    public static void main(String[] args) {
        TestObject[] array = new TestObject[4];
         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-20 03:26

    What happens if you want to fill up your array with real objects that are subclasses of TestObject, or which are constructed with non-default constructors? In the real world, you rarely want an array with a bunch of identical objects.

提交回复
热议问题