Implementing Monads in Java 8
You cannot implement a fully type-safe Monad interface in Java. The correct signature for flatmap would be something like <R> M<R> flatMap(Function<T, M<R>> f)
, but this is not expressible in Java. This M<R>
expression is called a higher-kinded type.