AutoArrayList

import java.util.ArrayList; 

public class AutoArrayList extends ArrayList<Object>{ 

private static final long serialVersionUID = 1L; 

private Class itemClass; 

public AutoArrayList(Class clz){ 
    this.itemClass = clz; 
} 

@Override 
public Object get(int index) { 
try{ 
    while(index>=size()){ 
        add(itemClass.newInstance()); 
    } 
}catch(Exception e){ 
    e.printStackTrace(); 

} 
    return super.get(index); 
} 
} 

你可能感兴趣的:(ArrayList)