I have the following code:
public interface StackInterface<T> {
public T pop();
public void push(T n);
}
public class myStack<T> implements StackInterface<Node<T>> {
Node<T> head;
Node<T> next;
Node<T> tail;
public myStack(T t) {
head = new Node<T>(t);
head.next = null;
tail=head;
}
public myStack() {
head = null;
tail=head;
}
public Node<T> pop() {
if(head==null) {
return null;
}
Node<T> t= head;
head=head.next;
return t;
}
public void push(T n) {
Node<T> t = head;
head = new Node<T>(n);
head.next = t;
}
}
This code shows the following errors:
on the class declaration line; it says that it does not implement the method public void push(T n); and on public void push(T n) line it says:
The method push of myStack has the same erasure as push of StackInterface but does not override it.
The method prototypes are identical; adding @Override does nothing. Why is this happening?