title: Java Stack Cannot invoke push(E) on the array type E[]
body: <p>I have a probelm. I know that i have to allocate a new stack of a double size, if my stack is full. I have tryed to use a temp Stack, but during the compilation, I have see an error on a 55 line. The error is "Cannot invoke push(E) on the array type E[]". I have no idea why i can't do this metod.</p>
  
  <pre><code>package stack;
  
  import exception.EmptyStackException;
  
  import exception.FullStackException;
  
  public class ArrayStack&lt;E&gt; implements Stack&lt;E&gt;{
  
  protected int capacity;
  protected static final int CAPACITY = 1000;
  protected E S[];
  protected int top = -1;
  
  @SuppressWarnings("unchecked")
  public ArrayStack(int capacity){
      this.capacity = capacity;
      this.S = (E[]) new Object[this.capacity];
  }
  
  public ArrayStack(){
      this(CAPACITY);
  }
  
  @Override
  public int size() {
      return top+1;
  }
  
  @Override
  public boolean isEmpety() {
      return (this.top &lt; 0);
  }
  
  @Override
  public E top() throws EmptyStackException {
      if(isEmpety())
          throw new EmptyStackException("Stack Vuoto.");
      return this.S[top];
  }
  
  @Override
  public void push(E element) throws FullStackException, EmptyStackException {
      if(size() == capacity){
          this.tempStack();
  
      }
      //throw new FullStackException("Stack Pieno.");
      this.S[++top] = element;
  }
  
  private void tempStack(){
      E tempS[] = (E[]) new Object[this.capacity];
      E tempEl;
      while(isEmpety()){
          tempEl = this.pop();
          tempS.push(this.pop());
      }
      this.capacity += this.capacity;
      this.S = null;
      this.S = (E[]) new Object[this.capacity];
  }
  
  public void union(Stack&lt;E&gt; s){
  
  }
  
  @Override
  public E pop() throws EmptyStackException {
      E element;
      if(isEmpety())
          throw new EmptyStackException("Stack Vuoto.");
      element = S[top];
      this.S[top--] = null;
      return element;
  }
  
  }
  </code></pre>