How Pattern Matching of instanceof can help in Type Checking in Java? Example

Java 16 introduces pattern matching for the instanceof operator, making it possible to use instanceof in a more concise and readable way.

Soma
Javarevisited

--

How Pattern Matching and instanceof can help in Type Checking in Java? Example

Hello Java developers, if you follow new Java releases closely then you may know about new and exciting features they keep introduce every six month like Text Blocks, Modules, Sealed Class, Records, Switch expression and now pattern matching for the instanceof operator.

The instanceof operator is not new in Java and its one of the lessor known and under rated tool to check the type of object in runtime but with new enhancement I believe it will get the popularity and love of Java developer which it should always get.

In past few articles I have been sharing my experience on Microservices like 50 Microservices Interview questions which I shared earlier as well my article about SAGA Design Pattern and Monolitihic vs Microservices architecture and in this article I will talk about instanceOf operator of Java programming language.

For those who don’t know, Java 16 introduces pattern matching for the instanceof operator, making it possible to use instanceof in a more concise and readable way as shown below:

--

--

Soma
Javarevisited

Java and React developer, Join Medium (my favorite Java subscription) using my link 👉 https://medium.com/@somasharma_81597/membership