So I have a basic stack implementation here using an interface in Java and I had a couple of questions on how all this works,
public class ArrayStack<T> implements ArrayStackADT<T> {
private T[] ArrayStack;
private int top;
public ArrayStack() {
ArrayStack = (T[]) new Object[20];
}
So I do understand that this line ArrayStack = (T[]) new Object[20];
creates an array implementation of a Stack with size 20 but I'm confused about what (T[])
and 'new Object
' do and why they are required there? Could anyone describe it in Layman terms?