1 2 public class Main { 3 public static void main(String[] args) { 4 Main main = new Main(); 5 main.setReadOnly(false); 6 main.add(main); 7 } 8 9 private boolean readOnly; 10 private int size = 0; 11 private Object[] elements = new Object[1]; 12 public void add(Object element){ 13 if(!readOnly){ 14 if(配列が一杯だったら){ 15 Object[] newElements = new Object[elements.length+10]; 16 for(int i = 0;i < size; i++) 17 newElements[i] = elements[i]; 18 elements = newElements; 19 } 20 elements[size++] = elements; 21 } 22 } 23 public void setReadOnly(boolean readOnly) { 24 this.readOnly = readOnly; 25 } 26 27 }