mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-17 15:50:53 +07:00
23 lines
656 B
Java
23 lines
656 B
Java
import java.util.*;
|
|
|
|
class Test {
|
|
|
|
List<String> getList(Function<Object, String> 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<String>(), function);
|
|
}
|
|
|
|
<R, S, T extends Collection<S>> T transform(Iterable<? extends R> oldCollection, T newCollection, Function<R, S> function) {
|
|
for (R r : oldCollection) {
|
|
newCollection.add(function.apply(r));
|
|
}
|
|
return newCollection;
|
|
}
|
|
|
|
interface Function<X, Y> {
|
|
Y apply(X input);
|
|
}
|
|
} |