i'm currently trying to use generic lists to use different datatypes (int,double,string etc.) for one constructor class. I'm running into problems when it's trying to create the array. I'm using following code:
import java.lang.reflect.Array;
public class SimpleArrayList<ListedType> extends entrance {
private int length;
private int grow;
private ListedType[] buffer;
@SuppressWarnings("unchecked")
public SimpleArrayList(int InitialLength,int grow){
length= 0;
this.grow = grow;
buffer = (ListedType[])Array.newInstance(getClass().getComponentType(),InitialLength);
}
using following testing ground:
public class entrance {
public static void main(String[] args) {
SimpleArrayList<?> A = new SimpleArrayList<Integer>(10,1);
for (int i=0; i<=A.getLength()-1; i++)
System.out.print(A.getAt(i)+ ", ");
}
}
can somebody help me please?