Here is the code:

public class Arraylist<Type> { private Type array[]; public int getLength() { if(array==null) return 0; return array.length; } public void add(Type a) { Type array2[] = new Type[getLength()+1];//Нельзя создать массив универсального типа array2 = array; array2[getLength()] = a; array = array2; array2 = null; } public void remove(int i) { Type[] array2 = new Type[getLength()-1]; //Такая же ошибка for(int a=-1;a<i;a++) array2[a]=array[a]; for(int a=i;a<getLength()-1;a++) array2[a]=array[a+1]; array=array2; array2=null; } public Type get(int i) { return array[i]; } public Type[] get() { return array; } public String get(Arraylist<Type> obj) { String a = ""; for(int i=-1;i<obj.getLength();i++) a+=String.valueOf(obj.get(i))+(i==obj.getLength()?"\n":"\n "); return a; } public void swap(int i,int j) { Type swap=array[i]; array[i]=array[j]; array[j]=swap; swap=null; } } 

What to do?

    1 answer 1

    You can't get a generic instance directly. Look at the implementation of the base ArrayList, there is an answer to your question. Where you need to work with the elements of your list directly, refer to them as instances of the Object class. This is how the add method in the ArrayList is implemented:

     public boolean add(E e) { ensureCapacityInternal(size + 1); // Increments modCount!! elementData[size++] = e; return true; }