I am trying to make a generic Stack class as shown
public class Stack<T> {
public Stack(Class<T[]> type, int capacity) {
this.capacity = capacity;
array = type.cast(Array.newInstance(type,capacity));
}
}
but am unsure of what to put in for type when instantiating since I thought of doing
MyClass[] c = new MyClass[0];
myStack = new Stack<MyClass>(c.getClass(), 100);
however I get the following error of
Required type: Class <MyClass[]>
Provided: Class <capture of ? extends MyClass[]>
so I thought of using
c.getClass().cast()\
but I am unsure of what to put inside of cast() since it won't take
Class<MyClass[]>
now I am stuck.