I'm trying to push Integer onto a generic array. Here's my code:
import java.lang.reflect.Array;
public class StackMain
{
public void main (String[]args)
{
Integer[] oneStack = null;
Integer a = new Integer("1");
oneStack = (Integer[])Array.newInstance(Integer.class, 10);
push(a, oneStack);
}
}
public class Stack<T>
{
private T[] oneStack;
public void push(T item, T[] array)
{
array[1] = item; //dummy method for testing
}
}
But push(a, oneStack) gives me a "cannot find symbol" error for some reason. Should I use Integer[] instead of T[]? I thought that Integer was a generic ...
Stack<T>.pushintend to do? It isn't clear to me whether you want to pushitemtoarrayoroneStack.