← All Exercises

Pattern Matching for Switch

intermediatejava~20min

Background

Pattern matching in switch reduces boilerplate for type-based dispatch in modern Java.

Problem

Use pattern matching in switch to handle different object types concisely without instanceof chains.

Input

Objects of various types

Output

Type-specific results

Sample tests

Sample 1

Input: switch on Object with patterns
Expected: type-specific handling

Your solution

Learning objective

Learn modern Java pattern matching features