Skip to content

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Pattern Matching for Switch Examples

This repository contains several examples for "Pattern Matching for switch", a feature described in JEP 441 and released in Java 21.

I walk through these examples in my Java Magazin article Java 21: Pattern Matching for switch (German).

An overview of all forms of pattern matching in Java is in the article Pattern Matching in Java: instanceof, switch, and Record Patterns (German version: Pattern Matching in Java: instanceof, switch und Record Patterns).

How to Run

You need Java 21 or newer. Every example is a single file that the java command runs directly, for example:

cd src/main/java/eu/happycoders/java21/patternmatching
java Example05_SwitchWithTypePattern.java

Other Java 21 Examples

You might also find these GitHub repositories interesting:

Virtual Threads:

Structured Concurrency:

Scoped Values:


Additional Resources


Java Versions PDF Cheat Sheet

Stay up-to-date with the latest Java features with this free PDF Cheat Sheet!

Java Versions PDF Cheat Sheet Mockup

  • Avoid lengthy research with this concise overview of all Java versions from Java 10 to Java 27.
  • Discover the innovative features of each new Java version, summarized on a single page.
  • Impress your team with your up-to-date knowledge of the latest Java version.

👉 Download the free Java Versions PDF

(Hier geht's zur deutschen Version → Java-Versionen PDF)


The Big O Cheat Sheet

With this free 1-page PDF cheat sheet, you'll always have the 7 most important complexity classes at a glance.

Big O PDF Cheat Sheet Mockup

  • Always choose the most efficient data structures and thus increase the performance of your applications.
  • Be prepared for technical interviews and confidently present your algorithm knowledge.
  • Become a sought-after problem solver and be known for systematically tackling complex problems.

👉 Download the free Big O Cheat Sheet

(Hier geht's zur deutschen Version → O-Notation Cheat Sheet)


HappyCoders Newsletter

👉 Want to stay on top of modern Java? Sign up for the HappyCoders newsletter – Modern Java: new versions & features, performance, and JVM insights – once a month.

(Hier geht's zur deutschen Version → HappyCoders-Newsletter deutsch)


🇩🇪 An alle Java-Entwickler:innen, die durch fundierte Kenntnisse über Datenstrukturen besseren Code schreiben wollen

Trage dich jetzt unverbindlich auf die Warteliste von „Mastering Data Structures in Java“ ein, und erhalte das beste Angebot!

Mastering Data Structures Mockup

👉 Zur Warteliste

Releases

Packages

Used by

Contributors

Languages