I was practicing an algorithmic concept called Recursion. At first, I write a recursive method for calculating
Factorial.
A simple solution:
The above code satisfied the requirements, but I try to do the same using anonymous lambda based functions
and the problem began.
However, this will not work and will produce a compiler error:
The local variable factorial may not have been initialized
Lambdas are most often used to define anonymous functions. A recursive function must call itself. An
anonymous lambda can’t call itself since it has no name, so it can’t be recursive.
The problem above is that we are referencing a variable while initializing it. So it is not yet initialized.
After spending a lot time trying to resolve the above error, I found the solution here.
I just want to let you know about some problems with recursive and Lambdas in Java 8