# Nice and Naughty Cases of Pattern Matching

DevFeed: [Nice and Naughty Cases of Pattern Matching](<https://devfeed.tech/articles/nice-and-naughty-cases-of-pattern-matching-23025.md>)

Original publisher: [Read original article](<https://www.javaadvent.com/2025/12/nice-and-naughty-cases-of-pattern-matching.html>)

Author: Cay Horstmann

Published: 2025-12-08T02:02:26Z

Content type: article

Language: en

Sources: [Java Advent Calendar](<https://devfeed.tech/sources/java-advent-calendar.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [2025](<https://devfeed.tech/tags/2025.md>), [article](<https://devfeed.tech/tags/article.md>), [enums](<https://devfeed.tech/tags/enums.md>), [exhaustive](<https://devfeed.tech/tags/exhaustive.md>), [expression](<https://devfeed.tech/tags/expression.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [java](<https://devfeed.tech/tags/java.md>), [java-language](<https://devfeed.tech/tags/java-language.md>), [pattern-matching](<https://devfeed.tech/tags/pattern-matching.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [programming](<https://devfeed.tech/tags/programming.md>), [sealed](<https://devfeed.tech/tags/sealed.md>), [statement](<https://devfeed.tech/tags/statement.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [types](<https://devfeed.tech/tags/types.md>)

## AI overview

This article examines Java pattern matching in switch and instanceof, explaining when it fits data-oriented programming, when it becomes an antipattern, and how it interacts with legacy behavior. It uses sealed interfaces, records, enums, and JSON values to illustrate exhaustive pattern matching.

## Source excerpt

Since Java 14, the Java switch and instanceof statements have been enhanced, in multiple phases, to support pattern matching and a "data-oriented" programming style. In this article, I explore when this programming style is beneficial, and why. I look at the sweet spot of perfect pattern usage, absolute antipatterns where it should not be used, [...] The post Nice and Naughty Cases of Pattern Matching appeared first on JVM Advent.