Records and Record Patterns
This chapter includes 19 problems that cover, in detail, the Java records introduced in JDK 16 (JEP 395), and record patterns introduced as a preview feature in JDK 19 (JEP 405), as a second preview feature in JDK 20 (JEP 432), and as a final feature in JDK 21 (JEP 440).
We start by defining a simple Java record. We continue by analyzing a record’s internals, what it can and cannot contain, how to use records in streams, how they improve serialization, and so on. We are also interested in how we can use records in Spring Boot applications, including JPA and jOOQ technologies.
Next, we focus on record patterns for instanceof
and switch
. We will talk about nested record patterns, guarded record patterns, handling null
values in record patterns, and so on.
At the end of this chapter, you’ll have mastered Java records. This is great because records are a must-have for any Java developer who wants to adopt the coolest Java features...