<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pattern-Matching on Devops Monk</title><link>https://devops-monk.com/tags/pattern-matching/</link><description>Recent content in Pattern-Matching on Devops Monk</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 04 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://devops-monk.com/tags/pattern-matching/index.xml" rel="self" type="application/rss+xml"/><item><title>Pattern Matching for instanceof (JEP 394): Smarter Type Checks</title><link>https://devops-monk.com/tutorials/java17/pattern-matching-instanceof/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java17/pattern-matching-instanceof/</guid><description>Finalized in Java 16 (JEP 394). Available in all Java 16+ releases, including Java 17. Previous previews: Java 14 (JEP 305) and Java 15 (JEP 375).
The Problem: The instanceof-Cast Dance Every Java developer has written this pattern:
// Java 11 — check, then cast if (obj instanceof String) { String s = (String) obj; // cast is logically redundant System.out.println(s.toUpperCase()); } The instanceof check already verified the type. The cast on the next line is conceptually redundant — the compiler could infer that obj is a String in the if body.</description></item><item><title>Pattern Matching for switch (JEP 406): Type Dispatch in switch (Preview)</title><link>https://devops-monk.com/tutorials/java17/pattern-matching-switch-preview/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java17/pattern-matching-switch-preview/</guid><description>Preview Feature in Java 17 (JEP 406 — First Preview). Requires --enable-preview. This feature evolved through Java 18 (JEP 420), Java 19 (JEP 427), Java 20 (JEP 433), and was finalized in Java 21 (JEP 441). The Java 21 final version has minor syntax differences from this Java 17 preview — documented below.
Enabling Preview Features Pattern matching for switch requires --enable-preview in Java 17. Add to your build tool:</description></item><item><title>Pattern Matching for switch (JEP 441): Type Dispatch Without the Boilerplate</title><link>https://devops-monk.com/tutorials/java21/pattern-matching-switch/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java21/pattern-matching-switch/</guid><description>The Problem: Cascading instanceof Chains Any Java codebase handling multiple subtypes has code like this:
// Java 16 and earlier — the bad old way static double calculateArea(Shape shape) { if (shape instanceof Circle) { Circle c = (Circle) shape; return Math.PI * c.radius() * c.radius(); } else if (shape instanceof Rectangle) { Rectangle r = (Rectangle) shape; return r.width() * r.height(); } else if (shape instanceof Triangle) { Triangle t = (Triangle) shape; return 0.</description></item><item><title>Record Patterns (JEP 440): Destructuring Records with Power and Precision</title><link>https://devops-monk.com/tutorials/java21/record-patterns/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java21/record-patterns/</guid><description>Records Recap Records (Java 16, JEP 395) are transparent carriers of immutable data:
record Point(int x, int y) {} record ColoredPoint(Point point, String color) {} record Line(Point start, Point end) {} The compiler generates a constructor, accessor methods (x(), y()), equals, hashCode, and toString. Before Java 21, accessing record components required calling accessor methods:
Object obj = new ColoredPoint(new Point(3, 4), &amp;#34;red&amp;#34;); if (obj instanceof ColoredPoint cp) { int x = cp.</description></item><item><title>Unnamed Patterns and Variables (JEP 443): Writing Intent-Clear Code</title><link>https://devops-monk.com/tutorials/java21/unnamed-patterns/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java21/unnamed-patterns/</guid><description>Preview Feature — Requires --enable-preview at compile and runtime. The _ identifier was reserved in Java 9; this JEP gives it formal semantics.
The Problem: Forced Naming of Unused Things When pattern matching, you often care about only some components of a matched structure. But the syntax forces you to name everything:
record Point(int x, int y) {} record ColoredPoint(Point point, String color) {} record Box(ColoredPoint cp, int weight) {} // You only care about the color — but must name everything else if (obj instanceof Box(ColoredPoint(Point(int x, int y), String color), int weight)) { System.</description></item></channel></rss>