Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. interface Function<R> {
  2.     public R call(Object... args);
  3. }
  4.  
  5. abstract class Function1<R, A> implements Function<R> {
  6.     abstract public R call(A arg1);
  7.     public R call(Object... args) {
  8.         System.out.println("call: Generic");
  9.         return call((A)args[0]);
  10.     }
  11. }
  12.  
  13. class TestFunc extends Function1<Integer, Integer> {
  14.     public Integer call(Integer a) {
  15.         System.out.println("call: Real");
  16.         return a+2;
  17.     }
  18. }
  19.  
  20. class main {
  21.     public static void main(String[] args) {
  22.             Function<Integer> f = new TestFunc();
  23.             TestFunc f2 = (TestFunc)f;
  24.             Integer a = f.call(11);
  25.             System.out.println(a);
  26.             Integer b = f2.call(12);
  27.             System.out.println(b);
  28.     }
  29. }
Add Comment
Please, Sign In to add comment