If one runs the following code in java:
public class Testing {
public static void main(String[] args) {
TestObject[] array = new TestObject[4];
//array[0] = new TestObject();
System.out.println(Arrays.asList(array));
}
}
class TestObject {
String aString;
public TestObject() {
aString = "This has been initialized.";
}
}
It will print (null, null, null, null), and if array[0] = new TestObject(); is uncommented, then the first object will have a memory address (and not be null). I'm just confused to as to why Java wouldn't automatically call the constructor for each Object in an array when the array is first initialized properly. What are the advantages of the way it works right now? Is it a space issue (as in it would be too costly to do so)?
Maybe I've just overlooked something silly or I'm simply mistaken. This is not directly related to a problem I'm having, so if it's the wrong forum I apologize.
Array.fillmethods.