λ Tony's Blog λ

Java Trivia

Posted on May 31, 2010

Implement the missing function body. These rules must be followed:

  • No using null

  • No throwing an exception/error

  • Function must terminate

  • No side-effecting

  • No type-casing (instanceof)

  • No type-casting

How many different ways of achieving the objective?

  interface Function<A, B> {
    B apply(A a);
  }

  class C {
    static <A, B, C> Function<A, C> c(final Function<A, B> f,
                                      final Function<B, C> g) {
        .... todo
    }
  }