Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created August 20, 2009 11:20
Show Gist options
  • Save NicolasT/170997 to your computer and use it in GitHub Desktop.
Save NicolasT/170997 to your computer and use it in GitHub Desktop.
interface Function1<T1, R> {
public R apply(T1 v);
}
public class Functional {
public static void main(String[] args) {
Integer[] i = {1, 2, 3, 4};
foreach(new Function1<Integer, Object>() {
public Object apply(Integer v) {
System.out.println("" + v);
return null;
}
}, i);
}
private static <T> void foreach(Function1<T, Object> fun, T[] values) {
for(T o: values) {
fun.apply(o);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment