import java.util.*; class Test { List getList(Function function) { /* * When the first argument below is a raw type it turns red because IDEA thinks the return * type is Collection<>. javac and Eclipse don't care */ return transform(new ArrayList(), new ArrayList(), function); } > T transform(Iterable oldCollection, T newCollection, Function function) { for (R r : oldCollection) { newCollection.add(function.apply(r)); } return newCollection; } interface Function { Y apply(X input); } }