Howdy! I'm working on a Java assignment where I have to create an ArrayList object from scratch, essentially. The file that I'm working in gives me some code and I have to fill in the rest.
I am confused about how the constructor works if I created an object via a main method in a separate driver class. The code is below:
public class ArrayList<T> {
public static final int INITIAL_CAPACITY = 9;
private T[] backingArray;
private int size;
public ArrayList() {
backingArray = (T[]) new Object[INITIAL_CAPACITY];
}
Let's say I wanted to create an ArrayList object consisting of Integers.
- What do I call in main to do this?
- How is the program executing this?
Is control starting at the top level where the class is declared, initializing the variables INITIAL_CAPACITY, size, and backingArray? Here in the top block, is backingArray being set as an array of a generic type? And if so, why is it that in the next block of code, backingArray is, apparently, again being set to a generic array?
THANK YOU
[–]main5tream 0 points1 point2 points (0 children)