As a Java programmer, imagine having the option of skipping usage of the instanceof operator and explicit casting operators to retrieve a value from your objects. Pattern matching (JDK Enhancement Proposals (JEP) 305) addresses this pain point by adding type test patterns and constant patterns. It enhances the Java programming language to introduce functionality that enables you to determine the type of instances and derived classes, and access their members without using explicit casting.
In this chapter, we'll cover the following topics:
- Pattern matching
- Type test patterns
- Constant patterns