Inline functions
Higher-order functions are very helpful and they can really improve the reusability of code. However, one of the biggest concerns about using them is efficiency. Lambda expressions are compiled to classes (often anonymous classes), and object creation in Java is a heavy operation. We can still use higher-order functions in an effective way, while keeping all the benefits, by making functions inline.
The concept of inline functions is pretty old, and it is mostly related to C++ or C. When a function is marked as inline, during code compilation the compiler will replace all the function calls with the actual body of the function. Also, lambda expressions provided as arguments are replaced with their actual body. They will not be treated as functions, but as actual code. This makes bytecode longer, but runtime execution is much more efficient. Later, we will see that nearly all higher-order functions from the standard library are marked as inline. Let's look at the example....