Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JEP530 : Primitive Types in Patterns, instanceo...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
riko
March 24, 2026
Technology
60
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JEP530 : Primitive Types in Patterns, instanceof, and switch (Fourth Preview)
riko
March 24, 2026
More Decks by riko
See All by riko
JEP 527:Post-Quantum Hybrid Key Exchange for TLS 1.3
riko111
0
21
Other Decks in Technology
See All in Technology
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.3k
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
3
3.2k
Lambda MicroVMsは常駐サーバーの代わりに なるか? Kiro Crew を動かして検証してみた / Kiro Crew on Lambda MicroVMs
k_adachi_01
2
300
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
160
Apache Iceberg が拓く AI 時代のオープンレイクハウス
tomtanaka
0
130
AWS App Runnerから Cloudflare Workersへ移行した話
ryota09
0
110
Account Factory for Terraformによる 標準化されたアカウント発行の自動化
pensuke628
0
110
企業の現実世界をグラフで写し取る
sansantech
PRO
0
170
音声コミュニティを守るAI監視基盤_ 90%以上の入力削減を支えたServerless設計と運用判断
shuheioka123
0
110
AI Native Platform Engineering 〜PlatformとAgileで“作る速さ”を“価値”へ〜
uya116
0
350
行動するAIのためのオントロジー | DevRev — Encraft #26.pdf
dvrv_tknrszk
1
540
AIに書かせて、プラットフォームで縛る ― EKSプラットフォームで実践した責任境界と権限設計
elmodev09
1
930
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
270
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Are puppies a ranking factor?
jonoalderson
2
4k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
700
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
540
How Software Deployment tools have changed in the past 20 years
geshan
2
34k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
910
Building Adaptive Systems
keathley
44
3.2k
BBQ
matthewcrist
89
10k
Deep Space Network (abreviated)
tonyrice
0
320
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Transcript
JEP530: Primitive Types in Patterns, instanceof, and switch (Fourth Preview)
2026/03/24 JJUGナイトセミナー 「Java 26 リリース記念イベント」
自己紹介 2
JEP530の概要 「すべてのプリミティブ型を、 パターンマッチングで扱えるようにする」 以下の3つでプリミティブ型がフルサポートされる 1. instanceof演算子 2. switch文 / switch式
3. Record Pattern 3
プリミティブ型でパターンマッチング① int i = ...; if(i >= Byte.MIN_VALUE && <=
Byte.MAX_VALUE){ byte b = (byte)i; ... 4 int i = ...; if(i instanceof byte b){ ... こう書けるように • instanceofでプリミティブ型が使える
プリミティブ型でパターンマッチング② 5 long id = ...; switch(id){ case 1L ->
{} case 2L -> {} default -> {} } • 今までのswitchで使えたもの • int・char・byte・shortとそれらのラッパー, String, enum • 新しく使えるようになるもの • long, float, double, boolean
プリミティブ型でパターンマッチング③ 6 void process(Number n){ switch (n){ case int _
-> {} case double _ -> {} default -> {} } } • switchのcaseラベルでプリミティブ型が使える
プリミティブ型でパターンマッチング④ 7 record Point(int x, int y){} Object obj =
... //←ObjectとしてPointが渡された if(obj instanceof Point(byte x, byte y)){ ... // Pointの中身がbyteに収まる場合のみ処理 • レコードパターンと統合
リリースの歴史 JEP455 JDK23 Preview ↓ JEP488 JDK24 Second Preview ↓
JEP507 JDK25 Third Preview ↓ JEP530 JDK26 Fourth Preview 8
今回の変更点 2つの変更点が提案 1. 無条件の正確性(unconditional exactness)の定義の強化 2. switch構文における、より厳密な支配(dominance)チェックの 適用 9
Dominance(支配)の原則 • 到達不可能なcaseを防ぐため、広範なパターンが先に来たら コンパイラはエラーを出さなければならない Object o = "test"; switch (o){
case Object _ -> {} case String _ -> {} default -> {} } 10
パターンの「支配」判定の複雑化 • 参照型の場合はシンプル: • ObjectはStringを支配する(親クラスは子クラスを完全に覆う) という明確なルールがあった • プリミティブの導入による混乱 • 「intはbyteを支配するのか?」「Integerはintを支配するのか?」
int x = …; switch (x){ case byte _ -> {} case int _ -> {} default -> {} }; xの値によって当てはまるcaseが変わる 11
Unconditional Exactness(無条件の正確性)とは? 常に安全な変換かどうかの基準 • ある型Aから型Bへの変換が、実行時の具体的な値に依存せず、 常に情報損失なく(Exactlyに)行えること • byte → int:Unconditionally
Exactである • どんなbyteの値も絶対にintに収まる • int → byte:Unconditionally Exactではない • 100なら収まるが、1000なら収まらないなど、値に依存する • int → float:Unconditionally Exactではない • 大きな桁のintは、floatにすると下位の精度が落ちる 12 例
JEP530での再定義 ある型Tが型Uを支配するのは、UからTへの変換が Unconditionally Exactである場合に限る • コンパイラが、数学的に矛盾なく「到達不能コード」を判定し、 適切なエラーを出すようになった 13 int j
= …; switch (j){ case float f -> {} case 16_777_216 -> {} default -> {} };
2種類のUnconditionally Exact • Type-based • 入力値にかかわらず、型の性質のみで安全性が保証される変換 14 int x =
… switch (x){ case int _ -> {} case byte _ -> {} default -> {} }; byte→ int, int→long, float→double int→Integer, String→Object 例
2種類のUnconditionally Exact • Value-based • 定数式限定 コンパイラが値そのものを解析して、情報欠落がないと判定されたもの 15 byte x
= …; switch (x){ case 100 -> {} case 1000 -> {} default -> {} };
互換性が失われたもの • 以前はOKだった • OKだと、開発者がBに到達可 能性があると誤解するかも • 今回からエラーになった 16 interface
A {} interface B {} A a = …; switch (a){ case A -> {} case B -> {} };
まとめ • 統一感の向上 • プリミティブとオブジェクトの文法的な壁がなくなり、 一貫したコードが書ける • 安全性の向上 • オーバーフローや精度落ちをコンパイル時に安全にチェック
17