Value Classで何が変わる?

Value Classで何が変わる?

2026.11.28 JJUG CCC 2026 Fall 発表資料

Yuichi.Sakuraba

November 27, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

26 slides
  1. 等価? int x = 10; int y = 10; x

    == y; true プリミティブ型は値で比較 Integer s = new Integer(10); Integer t = new Integer(10); s == t; false 参照型は参照で比較 値で比較 : equals()
  2. 等価? Integer a = Integer.valueOf(10); Integer b = Integer.valueOf(10); a

    == b; true Integer c = Integer.valueOf(200); Integer d = Integer.valueOf(200); c == d; false -128から127はキャッシュ リテラル文字列もキャッシュ
  3. record Point(int x, int y) {} Point points[] = ...;

    常に参照をたどる必要あり キャッシュミスが発生しやすい Heap Point Point Point Point Point Point
  4. record Point(int x, int y) {} Point points[] = ...;

    Heap これを実現するのが Value Class
  5. 標準APIにおけるValue Class java.lang Integer, Long, Float, Double, Byte, Short, java.util

    Character, Boolean Optional, OptionalInt, OptionalLong, OptionalDouble java.time LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Duration 悲しいお知らせ: Stringは非Value Class
  6. Value Classの制限 Identityを使用する機能は使用不可 モニタ var date = LocalDate.now(); synchronized(date) {

    ... } IdentityException例外発生 弱参照系 WeakReference, SoftReference, PhantomReference
  7. 平坦化 value class LocalDate ... { int year; byte month;

    byte date; ... LocalDate[] Rect } LocalDate year tl 2026 month br 11 date 29 tl br null LocalDate LocalDate year tl 2027 month br 3 date 9 year tl 2026 month br 6 date 15 LocalDate[] 1 2026 11 29 1 2026 6 15 0 null 1 2027 3 9
  8. まだまだ続く...... Null許容性 アノテーションではなく言語仕様として JEP draft: Null-Restricted Value Class Types JEP

    draft: Null-Restricted and Nullable Types ジェネリクスのプリミティブ型サポート JEP 218: Generics over Primitive Types 型クラス JVMLS 2025: Growing the Java Language
  9. 参考 JEP JEP 401: Value Objects https://openjdk.org/jeps/401 JEP draft: Null-Restricted

    Value Class Types https://openjdk.org/jeps/8316779 JEP draft: Null-Restricted and Nullable Types https://openjdk.org/jeps/8303099 JEP 218: Generics over Primitive Types https://openjdk.org/jeps/218 Presentation Better Tools for Immutable Data (JavaOne 2026) https://youtu.be/BdLND9D81lI?si=3e3MgtHIp2xLOrg1 Value Classes Heap Flattening (JVMLS 2026) https://youtu.be/NF4CpL̲EWFI?si=TZ3fPK0ZjzYO1HUu

More Decks by Yuichi.Sakuraba

Other Decks in Technology