Created
October 15, 2017 06:54
-
-
Save jbgi/1a3697d380f2071eb8c2fd3ad259c011 to your computer and use it in GitHub Desktop.
Revisions
-
jbgi created this gist
Oct 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; interface Person { int age(); } interface People<T> { T fromList(List<Person> ps); List<Integer> getAges(T people); People<?> module = new People<List<Person>>() { public List<Person> fromList(List<Person> ps) { return ps; } public List<Integer> getAges(List<Person> people) { return people.stream().map(Person::age).collect(Collectors.toList()); } }; } // run with: // javac Program.java // java -cp . Program public class Program<T> { People<T> P; Program(People<T> P) {this.P = P;} void run() { T people = P.fromList(Arrays.asList(() -> 21, () -> 37)); System.out.println(P.getAges(people)); // print "[21, 37]" } public static void main(String[] args) { new Program<>(People.module).run(); } }