A developer and Java expert gives an overview of the instanceof operator in the recent versions of Java and how it can be used to improve your code.

Introduction

According to some surveys, like JetBrains’s great survey, Java 8 is currently the most used Java version, despite being a 2014 release.

This article is the first in a series of articles titled, “Going Beyond Java 8,” inspired by the contents of my book “Java for Aliens.” These articles will guide the reader step-by-step to explore the most important features introduced starting with Java 9. The aim is to make the reader aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.

In this article, we will look at an interesting novelty introduced in Java 14 as a preview feature (see related article). This is the first part of a complex feature known as pattern matching. It will affect various programming constructs in the future, for now, though, pattern matching is only available for use with the instanceof operator as a feature preview. This will radically change the way we use this operator.

#java #pattern matching #java 14 #instanceof

Going Beyond Java 8: Pattern Matching for instanceof
1.15 GEEK