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
riko
March 24, 2026
Technology
71
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
44
Other Decks in Technology
See All in Technology
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
260
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.6k
Refining Active Record
shugo
0
150
USB PDを使ってスマホを労わりたい
raspython3
0
180
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
1.1k
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
150
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
130
大型犬好きによるPugの紹介
yamanoku
1
160
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
140
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
430
Claude の新機能を、 出た日に触って社内に届けるまで
rfdnxbro
1
170
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
340
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Fireside Chat
paigeccino
43
4.1k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Docker and Python
trallard
47
4.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Six Lessons from altMBA
skipperchong
29
4.5k
The Language of Interfaces
destraynor
162
27k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
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