Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JavaにおけるNull非許容性
Search
Yuichi.Sakuraba
February 27, 2025
Technology
3.9k
2
Share
JavaにおけるNull非許容性
2025.02.28 Server-Side Kotlin Meetup 発表資料
Yuichi.Sakuraba
February 27, 2025
More Decks by Yuichi.Sakuraba
See All by Yuichi.Sakuraba
Java 25に至る道
skrb
3
290
Lazy Constant - finalフィールドの遅延初期化
skrb
0
3.5k
Language Update: Java
skrb
2
460
Java 30周年記念! Javaの30年をふりかえる
skrb
4
3.7k
あなたはJVMの気持ちを理解できるか?
skrb
6
32k
で、ValhallaのValue Classってどうなったの?
skrb
2
15k
Javaにおける関数型プログラミンへの取り組み
skrb
7
700
今こそ、ラムダ式を考える - なぜあなたはラムダ式を苦手と感じるのか
skrb
6
27k
今こそ、ラムダ式を考える - ラムダ式はどうやって動くのか
skrb
7
12k
Other Decks in Technology
See All in Technology
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
7.9k
データ定義の混乱と戦う 〜 管理会計と財務会計 〜
wonohe
0
170
AgentCore Managed Harness を使ってみよう
yakumo
2
280
AI時代のガードレールとしてのAPIガバナンス
nagix
0
340
要件定義の精度を高めるための型と生成AIの活用 / Using Types and Generative AI to Improve the Accuracy of Requirements Definition
haru860
0
230
『生成AI時代のクレデンシャルとパーミッション設計 — Claude Code を起点に』の執筆企画
takuros
2
1.7k
GKE Agent SandboxでAIが生成したコードを 安全に実行してみた
lamaglama39
0
150
巨大プラットフォームを進化させる「第3のROI」
recruitengineers
PRO
2
2k
色を視る
yuzneri
0
290
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
330
小説執筆のハーネスエンジニアリング
yoshitetsu
0
880
MySQL 9.7がやってきた ~これまでのあらすじと基本情報~ @ 日本MySQLユーザ会会2026年04月 / mysql97-yattekita
sakaik
0
140
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Code Reviewing Like a Champion
maltzj
528
40k
The Cult of Friendly URLs
andyhume
79
6.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
330
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
170
First, design no harm
axbom
PRO
2
1.2k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
140
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
160
Transcript
JavaにおけるNull非許容性 櫻庭 祐一
OpenJDK における新機能導入プロセス JEP: JDK Enhance Proposal Draft JEP 1st Preview
JEP n th Preview JEP Standard JEP 最低 2 回 差し戻しあり 本日のトピックは この段階 今後、 変更される可能性大
これまでの null に対する Java の取り組み null 参照型における 参照先がない状態 処理結果がない エラーなどを表す
本来の意味 副次的な意味 型アノテーション @NonNull List<@NonNull String> texts = ... Optional Optional<String> o = Optional.ofNullable(...); @NonNull が標準になっていないなど、 取り組みが成功しているとは言いがたい ...
Java の大きな流れ 重厚長大 長寿命 可変 オブジェクト 軽量 短寿命 不変 オブジェクト
ラムダ式 (Java 8) 処理とデータの分離 Record (Java 16) Sealed (Java 17) 代数的データ型 パターンマッチング (Java 16 ~ ) 型による処理の分岐 Value Class (Java ??) 値オブジェクト
Value Class 例) record Point(int x, int y) {} Point[]
Point x y Point x y Point x y Heap Point[] x y x y x y Heap value record Point(int x, int y) {} Value Class 化 ヒープ平坦化 参照をたどる必要なし オブジェクトヘッダーなし キャッシュミス低減
Value Class と Null 非許容型 Value Class によるヒープ平坦化 null があると余分なフラグやチェックが必要
最適化の効率が薄れる Null 非許容型の導入へ
Null 非許容型 / Null 許容型 JEP Draft: Null-Restricted Value Class
Types JEP Draft: Null-Restricted and Nullable Types https://openjdk.org/jeps/8316779 https://openjdk.org/jeps/8303099 String! Null 非許容型 (Null-Restricted Type) String? Null 許容型 (Nullable Type) ワイドニング変換 オブジェクト初期化順序の変更 配列初期化構文 ジェネリクス型パラメータへの適用 et al.
オブジェクト初期化順序の変更 class Foo { ... } class Bar extends Foo
{ Baz baz; Bar(Baz baz) { super(); this.baz = baz; } } スーパークラスのコンストラクタは 常にコンストラクタの先頭でコール このためフィールドが未初期化状態にある class Foo { ... } class Bar extends Foo { Baz baz; Bar(Baz baz) { this.baz = baz; super(); } } スーパークラスのコンストラクタを フィールド初期化後にコール可能
Conclusion 軽量不変オブジェクトへの流れ JVM 効率化としての Value Class と Null 非許容 Value
Class でなくても Null 非許容は使用可能 決まっていないことが多いが、 期待して待ちましょう