import java.util.function.Function; @FunctionalInterface interface SelfApplicable { OUTPUT apply(SelfApplicable input); } class Utils { public static SelfApplicable, Function>, Function>> y() { return y -> f -> x -> f.apply(y.apply(y).apply(f)).apply(x); } public static Function, Function>, Function> fix() { return Utils.y().apply(Utils.y()); } public static long fib(int m) { if (m < 0) throw new IllegalArgumentException("n can not be a negative number"); return Utils.fix().apply( f -> n -> (n < 2) ? n : (f.apply(n - 1) + f.apply(n - 2)) ).apply(m); } }