fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.function.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. List<Foo> list = new ArrayList<>();
  14. list.add(new Foo("Hello"));
  15. list.add(new Foo("World"));
  16. show(list, Foo::getFullName);
  17. }
  18. private static <T> void show(List<T> list, Function<T,String> f) {
  19. for (T t : list) {
  20. System.out.println(f.apply(t));
  21. }
  22. }
  23. }
  24.  
  25. class Foo {
  26. private final String s;
  27. public Foo(String s) {this.s = s;}
  28. public String getFullName() {
  29. return s;
  30. }
  31. }
Success #stdin #stdout 0.2s 33264KB
stdin
Standard input is empty
stdout
Hello
World