fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.function.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11.  
  12. @FunctionalInterface
  13. interface UnaryOperator<T> extends Function<T, T> {
  14. static UnaryOperator<Object> IDENTITY_FUNCTION = (k -> k);
  15. static <T> UnaryOperator<T> identity() {
  16. return (UnaryOperator)IDENTITY_FUNCTION;
  17. }
  18. }
  19.  
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. UnaryOperator<String> sameString = UnaryOperator.identity();
  23. UnaryOperator<Integer> sameInt = UnaryOperator.identity();
  24. System.out.println(sameString.apply("hello, world!"));
  25. System.out.println(sameInt.apply(123));
  26. }
  27. }
  28.  
Success #stdin #stdout 0.19s 320640KB
stdin
Standard input is empty
stdout
hello, world!
123