My question comes from this thread.
Consider this code:
public class Test {
static Function<Integer, Integer> fibLambda = null;
public static void main (String[] args) {
fibLambda = n -> n <= 2 ? 1 : fibLambda.apply(n - 1) + fibLambda.apply(n - 2);
System.out.println(fibLambda.apply(6));
}
}
The output above is 8.
What I don't get is that how fibLamdba
is initialized? It seems that I totally miss how the method invocation is done because I though that this code would produce a NPE.
Hope my question is clear
main
say?fibLambda =
. Why wouldn't it be set...? – DozyfibLamdba = .. fibLambda.someFunction(..);
– SimoniacfibLambda
is the one that exists at call time. – Dozy