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.6k
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
Lazy Constant - finalフィールドの遅延初期化
skrb
0
110
Language Update: Java
skrb
2
350
Java 30周年記念! Javaの30年をふりかえる
skrb
4
3.4k
あなたはJVMの気持ちを理解できるか?
skrb
5
28k
で、ValhallaのValue Classってどうなったの?
skrb
2
13k
Javaにおける関数型プログラミンへの取り組み
skrb
7
610
今こそ、ラムダ式を考える - なぜあなたはラムダ式を苦手と感じるのか
skrb
6
25k
今こそ、ラムダ式を考える - ラムダ式はどうやって動くのか
skrb
7
11k
Project Amberで変わる Javaのプログラミングスタイル
skrb
3
1.2k
Other Decks in Technology
See All in Technology
なぜインフラコードのモジュール化は難しいのか - アプリケーションコードとの本質的な違いから考える
mizzy
36
11k
CDKの魔法を少し解いてみる ― synth・build・diffで覗くIaCの裏側 ―
takahumi27
1
110
Redux → Recoil → Zustand → useSyncExternalStore: 状態管理の10年とReact本来の姿
zozotech
PRO
1
460
Copilotの精度を上げる!カスタムプロンプト入門.pdf
ismk
10
3.3k
技術の総合格闘技!?AIインフラの現在と未来。
ebiken
PRO
0
250
“それなりに”安全なWebアプリケーションの作り方
xryuseix
0
270
us-east-1 の障害が 起きると なぜ ソワソワするのか
miu_crescent
PRO
2
770
開発者から見たLLMの進化 202511
ny7760
1
170
Logik: A Free and Open-source FPGA Toolchain
omasanori
0
280
Design and implementation of "Markdown to Google Slides" / phpconfuk 2025
k1low
1
390
ソフトウェアエンジニアとデータエンジニアの違い・キャリアチェンジ
mtpooh
1
740
AWS IAM Identity Centerによる権限設定をグラフ構造で可視化+グラフRAGへの挑戦
ykimi
2
710
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Site-Speed That Sticks
csswizardry
13
960
We Have a Design System, Now What?
morganepeng
54
7.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Become a Pro
speakerdeck
PRO
29
5.6k
Thoughts on Productivity
jonyablonski
73
4.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
GitHub's CSS Performance
jonrohan
1032
470k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
310
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 非許容は使用可能 決まっていないことが多いが、 期待して待ちましょう