/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package generics; import java.util.Iterator; /** * * @author steve */ public class GenericArrayList implements MinGenericList { Object[] data = new Object[10]; int logical_size = 0; @Override public void add(V v) { if(logical_size == data.length) { // We aren't allowed to say "new T[...]" because Java // implements generics by erasure Object[] new_data = new Object[(int)(1.3*data.length)]; for(int i=0;i iterator() { return new Iterator() { int i=0; @Override public boolean hasNext() { return i < logical_size; } @SuppressWarnings("unchecked") @Override public V next() { return (V)data[i++]; } }; } public static void main(String[] args) { MinGenericList list = new GenericArrayList<>(); GenericListTest.test(list); } }