我试图实现堆栈,不知怎的,当我尝试运行代码时,编译器说它是“不兼容的类型”。请帮忙
class MyArrayStack<E> extends ArrayList<E> implements Stack<E> {
int key,data,size = 0;
int[] array = new int[12];
int element;
public void push(E e) {
data = (int) e;
array[size] = data;
size++;
System.out.println("The Element is inserted Successfully");
}
}
答案 0 :(得分:0)
java.util.Stack是一个类,而不是一个接口。您可以删除ArrayList
import java.util.Stack;
class MyArrayStack<E> extends Stack<E> {
int key, data, size = 0;
int[] array = new int[12];
int element;
public E push(E e) {
data = (int) e;
array[size] = data;
size++;
System.out.println("The Element is inserted Successfully");
return e;
}
}