I'm creating an array based stack class in java, but I'm also forced to use the class
public class MyStack<E> implements Stack<E>.
My pop and peek are also in form of public E pop()/ public E peek().
I can't figure out how to use formats and create an array.
The size of array has to be 128, and I tried setting
private E[] Stack = new Object[128]
but it gives bunch of warnings and I can't search how to deal with this Object type. I tried using it by typecasting (int) or (char) each time I use item in the stack, but I'm getting a ClassCastException. For example, I tried using (int) tmp = (int)MyStack.pop();
and am getting the ClassCastException when I use the Object type.
Can anyone help me understand how this Stack, or works (or give a directing link to some well-written explanation) or tell me anywhere else I'm misguided?
Thanks!