import java.util.*;
class Higher {
interface Fun { // Interface for objects of functional type
B call (A arg); // which must provide a "call" method
}
static List map (Fun f, List xs) {
List ys = new ArrayList (xs.size());
for (A x : xs) {
ys.add(f.call(x)); // here we apply the interface
}
return ys;
}
// Example: apply function (*3) on all list elements
public static void main (String[] args) {
List a = Arrays.asList(1,2,3,4,5);
a = map(x -> x * x, a);
System.out.println(a);
}
}