I am trying to implement a Monad interface in Java 8 following [this article](https://dzone.com/articles/functor-and-monad-examples-in-plain-java) however I've got the following compiling errors

---

2 errors found:

* > 
> File:FunctorsMonads.java [line: 36]
> 
> 
> Error: FOptional is not abstract and does not override abstract method flatMap(java.util.function.Function>) in Monad
> 
> 
>
* > 
> File:FunctorsMonads.java [line: 50]
> 
> 
> Error: name clash: flatMap(java.util.function.Function>) in FOptional and flatMap(java.util.function.Function) in Monad have the same erasure, yet neither overrides the other
> 
> 
>

---

The `Functor` interface works just fine. Any help is much appreciated.

Here is the code:

```
import java.util.function.Function;

public class FunctorsMonads {

  public static void main(String[] args) {
    System.out.println(tryParse("47"));
    System.out.println(tryParse("a"));

    FOptional<String> str = FOptional.of("47");
    System.out.println(str);
    FOptional<FOptional<Integer>> num = str.map(FunctorsMonads::tryParse);
    System.out.println(num);
    FOptional<Integer> num2 = str.flatMap(FunctorsMonads::tryParse);
    System.out.println(num2);
  }

  static FOptional<Integer> tryParse(String s){
    try {
      final int i = Integer.parseInt(s);
      return FOptional.of(i);
    } catch (NumberFormatException e) {
      return FOptional.empty();
    }
  }
}

interface Functor<T, F extends Functor<?, ?>> {
  <R> F map(Function<T, R> f);
}

interface Monad<T, M extends Monad<?, ?>> extends Functor<T, M> {
  M flatMap(Function<T, M> f);
}

//class FOptional<T> implements Functor<T, FOptional<?>>
class FOptional<T> implements Monad<T, FOptional<?>> {
  private final T valueOrNull;

  private FOptional(T valueOrNull) {
    this.valueOrNull = valueOrNull;
  }

  public <R> FOptional<R> map(Function<T, R> f) {
    if (valueOrNull == null)
      return empty();
    else
      return of(f.apply(valueOrNull));
  }

  public <R> FOptional<R> flatMap(Function<T, FOptional<R>> f) {
    if (valueOrNull == null)
      return empty();
    else
      return f.apply(valueOrNull);
  }

  public static <T> FOptional<T> of(T a) {
    return new FOptional<T>(a);
  }

  public static <T> FOptional<T> empty() {
    return new FOptional<T>(null);
  }

  @Override
  public String toString() {
    return getClass().getName() + "<" + valueOrNull + ">";
  }
}

```

**Edit:**  

I have added the following lines in the main method as a litmus test of the implementation's correctness:  

`FOptional<Integer> num2 = str.flatMap(FunctorsMonads::tryParse);
 System.out.println(num2);`