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 配列を拡大 16 } 17 配列に要素を追加 18 } 19 } 20 public void setReadOnly(boolean readOnly) { 21 this.readOnly = readOnly; 22 } 23 24 }