Java functional-style programming in a nutshell
As usual, this section is meant to highlight and refresh the main concepts of our topic and to provide a comprehensive resource for answering the fundamental questions that may occur in a technical interview.
Key concepts of functional-style programming
So, the key concepts of functional programming include the following:
- Functions as first-class objects
- Pure functions
- Higher-order functions
Let's briefly dive into each of these concepts.
Functions as first-class objects
Saying that functions are first-class objects means that we can create an instance of a function as having a variable referencing that function instance. This is like referencing a String
, List
, or any other object. Moreover, functions can be passed as parameters to other functions. However, Java methods are not first-class objects. The best we can do is to rely on Java lambda expressions.
Pure functions
A pure function...