Couldn't find elsewhere, so here goes: I'm trying to create a generic class that contains an array holding objects of the given type. I have the rest of the code somewhat working, but for some reason I can't call my add method with the type as a parameter. Here's the example:
public class Generic<E extends Item> {
private E[] items = (E[])(new Object[5]);
public void add(E neu) {
this.items[0] = neu;
}
public void problematic(Class<E> clazz) {
E neu = clazz.newInstance();
this.items.add(neu); // this line is the problem
}
}
The given error is "Cannot invoke Add(E) on the array type E[]"
ArrayList.