Lambda Expressions
In this chapter, we will cover lambda expressions, which is one of my favorite features. Introduced in Java 8, lambda expressions (lambdas) brought functional programming to Java. First, we will define a functional interface and its relationship with lambdas. We will demonstrate both custom and API-based lambda expressions. We will also explain the concept of “final or effectively final” concerning local variables used inside a lambda expression.
After that, we will cover method references. We will discuss and present example code showing bound, unbound, static, and constructor method references. Lastly, we will explain the critical nature of context in understanding method references.
This chapter covers the following main topics:
- Understanding lambda expressions
- Exploring functional interfaces from the API
- Mastering method references