内部イテレータ風
"iterate with Proc"のJava版?
interface Procedure { void call(Object o); } class ForEachList extends java.util.ArrayList { ForEachList(Object array) { super(java.util.Arrays.asList(array)); } void each(Procedure c) { for (int i = 0; i < size(); i++) { c.call(get(i)); } } } class Main { public static void main(String args) { Procedure c = new Procedure() { public void call(Object o) { System.out.print("/*" + o + "*/"); } }; (new ForEachList(new Object[]{"1", "3", "2", "A"})).each(c); } }