title: Java: implementing a stack( pile) with ArrayList working with different types
body: <p>I'm building two classes: <code>class Stack</code> which implements a stack using <code>ArrayList</code> with <code>get</code> and <code>remove</code>, and <code>class Test2</code> which uses <code>Stack</code> to create stacks of chosen(in <code>Test2</code>) variables. In my example, I chose strings, but I'd like it to work with different types as well.</p>
  
  <p>These are the classes:</p>
  
  <pre><code>import java.util.*;
  public class Stack{
    ArrayList pila;
  
    public void push(Object o) {
          pila.add(o);
      }
    public Object pop() {
          if (!pila.isEmpty())
              return pila.remove(pila.size()-1);
        else return null;
    }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>import java.util.*;
  public class Test2{
    public static void main(String args[]) {
      String a = "mario";
      String b = "luigi";
      String c = "tony";
      Stack s = new Stack();
      s.pila = new ArrayList&lt;String&gt;();
      s.push(a);
      s.push(b);
      s.push(c);
      for (int i=0; i &lt;3; i++) System.out.println(s.pop());
    }
  }
  </code></pre>
  
  <p>It is working but it gives me the following warning when I compile <code>Stack</code>, and I wonder if this was the right way to do that.</p>
  
  <pre><code>Stack.java:6: warning: [unchecked] unchecked call to add(E) as a
  member of the raw type ArrayList
                   pila.add(o);
                           ^   where E is a type-variable:
       E extends Object declared in class ArrayList
  </code></pre>