// Funktionen
public static <T1,T2> List<T2> map(UnaryOp<T1,T2> obj,List<T1> l)
{
// Determine the dynamic type of the list
Class<? extends List> c = l.getClass();
try {
// Create a result list of the same List type
List<T2> result = c.newInstance();
//type.cast(type.newInstance());
// Copy elements satifying p
for ( T1 x : l )
result.add(obj.op(x));
return result;
}
catch (Exception e) {
return null;
}
}
public interface UnaryOp<T,U> {
U op(T x);
}
public class Sign implements UnaryOp<Integer,Integer> {
public Integer op(Integer x) {
return x.compareTo(0);
}
}