import java.util.Collection; class Test { public static final UnaryFunction unaryFunction = new UnaryFunction() { public Object execute(Object o) throws RuntimeException { return null; } }; public static void someMethod() { transformCollection(null, unaryFunction, null); } public static void transformCollection(Collection input, UnaryFunction transform, Collection output) throws X { for (A a : input) { B b = transform.execute(a); output.add(b); } } } interface UnaryFunction { public B execute(A a) throws X; }