import java.util.ArrayList; import java.util.Collection; interface Sink { void flush(T t); } class SimpleSinkImpl implements Sink { public void flush(T t) {} } public class Test { private T writeAll(Collection coll, Sink snk) { T last = null; for (T t : coll) { last = t; snk.flush(last); } return last; } public void test1() { Sink s = new SimpleSinkImpl(); Collection cs = new ArrayList(); cs.add("hello!"); cs.add("goodbye"); cs.add("see you"); String str = this.writeAll(cs, s); } public static void main(String[] args) { Test test = new Test(); test.test1(); } }