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
2
3.5k
JavaにおけるNull非許容性
2025.02.28 Server-Side Kotlin Meetup 発表資料
Yuichi.Sakuraba
February 27, 2025
Tweet
Share
More Decks by Yuichi.Sakuraba
See All by Yuichi.Sakuraba
Language Update: Java
skrb
2
340
Java 30周年記念! Javaの30年をふりかえる
skrb
4
3.3k
あなたはJVMの気持ちを理解できるか?
skrb
5
27k
で、ValhallaのValue Classってどうなったの?
skrb
2
12k
Javaにおける関数型プログラミンへの取り組み
skrb
7
600
今こそ、ラムダ式を考える - なぜあなたはラムダ式を苦手と感じるのか
skrb
6
25k
今こそ、ラムダ式を考える - ラムダ式はどうやって動くのか
skrb
7
11k
Project Amberで変わる Javaのプログラミングスタイル
skrb
3
1.2k
String Templateによる文字列補間
skrb
4
4.6k
Other Decks in Technology
See All in Technology
生成AIとM5Stack / M5 Japan Tour 2025 Autumn 東京
you
PRO
0
240
PLaMoの事後学習を支える技術 / PFN LLMセミナー
pfn
PRO
9
4k
Adminaで実現するISMS/SOC2運用の効率化 〜 アカウント管理編 〜
shonansurvivors
4
400
実装で解き明かす並行処理の歴史
zozotech
PRO
1
630
extension 現場で使えるXcodeショートカット一覧
ktombow
0
220
Adapty_東京AI祭ハッカソン2025ピッチスライド
shinoyamada
0
200
『OCI で学ぶクラウドネイティブ 実践 × 理論ガイド』 書籍概要
oracle4engineer
PRO
2
140
職種別ミートアップで社内から盛り上げる アウトプット文化の醸成と関係強化/ #DevRelKaigi
nishiuma
2
160
The Cake Is a Lie... And So Is Your Login’s Accessibility
leichteckig
0
100
Optuna DashboardにおけるPLaMo2連携機能の紹介 / PFN LLM セミナー
pfn
PRO
2
920
ACA でMAGI システムを社内で展開しようとした話
mappie_kochi
1
300
英語は話せません!それでも海外チームと信頼関係を作るため、対話を重ねた2ヶ月間のまなび
niioka_97
0
130
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
237
140k
Designing for humans not robots
tammielis
254
26k
Embracing the Ebb and Flow
colly
88
4.8k
Practical Orchestrator
shlominoach
190
11k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
580
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
The Invisible Side of Design
smashingmag
301
51k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Speed Design
sergeychernyshev
32
1.1k
It's Worth the Effort
3n
187
28k
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 非許容は使用可能 決まっていないことが多いが、 期待して待ちましょう