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
4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaにおけるNull非許容性
2025.02.28 Server-Side Kotlin Meetup 発表資料
Yuichi.Sakuraba
February 27, 2025
More Decks by Yuichi.Sakuraba
See All by Yuichi.Sakuraba
Inside Stream API
skrb
1
950
Java 25に至る道
skrb
3
320
Lazy Constant - finalフィールドの遅延初期化
skrb
0
5.1k
Language Update: Java
skrb
2
530
Java 30周年記念! Javaの30年をふりかえる
skrb
4
4.1k
あなたはJVMの気持ちを理解できるか?
skrb
6
35k
で、ValhallaのValue Classってどうなったの?
skrb
2
16k
Javaにおける関数型プログラミンへの取り組み
skrb
7
760
今こそ、ラムダ式を考える - なぜあなたはラムダ式を苦手と感じるのか
skrb
6
28k
Other Decks in Technology
See All in Technology
DINO-EdgeQuery:Edge-First Polygon Decoding for Building Footprint Extraction from Satellite Imagery
lehupa
0
140
KAEN Company Deck
kaen
PRO
0
290
PM領域でのAI Agentの活用
lycorptech_jp
PRO
0
260
魔法少女がClaude Codeを監視する / ccportal-deck
noriyukitakei
3
130
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
790
AI時代におけるプロダクト横断勉強会の設計
zozotech
PRO
0
150
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
150
Webとヘルスデータ
yukukotani
0
170
[RSJ26] NarrativeFlow: Flow-Based Vision-Language-Action Model Using Robot Velocity Fields
keio_smilab
PRO
0
150
『止めない』を設計する — 制約の中で、事業の根幹を支える判断
hiroyaterui
0
160
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
190
DGX Sparkを2台使って いろいろ動かす話
sonoda_mj
1
120
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.7k
Ruling the World: When Life Gets Gamed
codingconduct
0
320
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
490
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
490
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.7k
WCS-LA-2024
lcolladotor
0
820
The Limits of Empathy - UXLibs8
cassininazir
1
630
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
590
Docker and Python
trallard
47
4.2k
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 非許容は使用可能 決まっていないことが多いが、 期待して待ちましょう