Why doesn't Java initialize Array Objects?

后端 未结 2 1941
被撕碎了的回忆
被撕碎了的回忆 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:34

    With new TestObject[4] you create an array, wich can hold 4 references to TestObject. So understand the difference between TestObject[] and TestObject:

    TestObject[] is a reference store for TestObject - objects. If you create a List you'll have to fill up the list with references too.

提交回复
热议问题