Why use functional style in Java?

Sergiy Yevtushenko - Dec 11 '19 - - Dev Community

While previous post shows how to transform traditional code into functional one, it does not provide answer why it is necessary.

There are several reasons and all of them are important and relevant. I believe that the main reason is the code reliability.

Any approach/tool/methodology/etc. which improves code reliability enables us to create more and more complex systems. This why we adopt every single technology which improves code reliability - testing/static code analyzers/etc.

By using functional style, as shown in previous post, we involve compiler to help cover both, successful and unsuccessful (or null/non-null), outcome of every single intermediate call. As a consequence, compiler helps us to eliminate whole classes of errors, including, for example, NPE. Yes, it still possible to shoot himself in the foot. But this intent must be clearly expressed in code with this approach.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player