NhacVibe
Ảnh bìa Java : Pattern Matching and Modern Java

Java : Pattern Matching and Modern Java

Oddly Yogi · 11 lượt xem · 13 thg 11, 2026

Mô tả

How does a program handle many different kinds of request safely, without a tangle of casts and if statements? In this video we learn pattern matching in modern Java. Like a sorting machine at a library's return slot that recognises the shape of each item and opens the right chute, a switch with patterns recognises each type and pulls its parts out in one step. We cover instanceof patterns and flow scoping, switch over sealed types with exhaustiveness checks, guards with when, case null, dominance, record patterns and nested deconstruction, unnamed variables with the underscore, module import declarations from Java 25, and markdown documentation comments with javadoc. Shelf gets typed commands for its desk, parsed from text and handled by one exhaustive switch.

Versions: Java 25 LTS (Eclipse Temurin 25.0.5).

In this chapter:
00:00 A return slot that recognises shapes
01:29 instanceof with a pattern
02:46 Switch over a sealed type
04:06 Guards, null and dominance
05:43 Record patterns
06:32 Unnamed variables with _
07:29 Nested patterns in Shelf
08:56 Typed desk commands
10:52 One switch for every request
12:32 The desk at work
14:10 Adding a new kind of request
15:09 Enums in an exhaustive switch
16:48 Data and behaviour, kept apart
17:33 Markdown documentation with javadoc
18:27 More modern Java
19:36 Wrap up

This is Chapter 10 of 15 in the "Java" series.
#Java #Java25 #Programming #LearnJava #PatternMatching