i'm currently working through generic classes and stacks. I've created a class with an arrayList and create methods for push, peek and pop.

Whenever I run the driver though I get an index of of bounds exception and i'm confused to why. Any help would be great:

```
GenericStack class

public class GenericStack <T> {

  public ArrayList<T> stack = new ArrayList<T>();

  private int top = 0; 

  public int size () {return top; };

  public void push (T element){

    stack.add(element);

    top++;    
  }

  public T pop() {

    if (top == -1) {
      return null;   //means stack is empty
    }

    T val = stack.get(top);

    stack.remove(top);

     top--;
     return val;
  }

  public T peek(){
    if (top == -1){
      return null;
    }

    T val = stack.get(top);

    return val;

  }
}

```

and my GenericDriver class

```
public class GenericDriver extends GenericStack {

public static void main (String [] args){

GenericStack<String> strings = new GenericStack<String>(); 

                    strings.push ( "hi");
                    strings.push ("how are you?");
                    strings.push ("Hi again");
                    strings.push ("One more");

    if (strings.size() == 0) {
      System.out.println("Stack is empty.");
    } else { 
      System.out.println("Stack contains " + strings.size() + " items.");
    {   
      System.out.println("top value: (using pop)  " + strings.pop()); 

      System.out.println("Stack now contains: " + strings.size() + " items");

      System.out.println("The new top value, using peek:  " + strings.peek());
    }
  }

```

If anyone could tell me why i'm getting this exception it'll be brilliant