If one runs the following code in java:
public class Testing {
public static void main(String[] args) {
TestObject[] array = new TestObject[4];
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.
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<TestObject>
you'll have to fill up the list with references too.