If you want to define a recursive function, use the canonical Javas method to implement the recursive function: method:
public static int fib(int n) { return n==0? 0: n==1? 1: fib(n-1)+fib(n-2); }
Then, if you need an instance that executes a functional interface , you can use the method reference:
Function<Integer, Integer> fib = MyClass::fib;
or
IntUnaryOperator fib0=MyClass::fib;
source share