Briefing

Engineering Craftsmanship: Building a Sovereign Immutable List in Java

competitors
by Satyadev Neti ·

Patch your Java projects to use the new ImmutableList implementation for efficient, thread‑safe, immutable lists.

What to do now

Patch your Java projects to use the new ImmutableList implementation for efficient, thread‑safe, immutable lists.

Summary

The article presents a new immutable singly‑linked list implementation for Java 21/25 that leverages sealed interfaces and records to create a sum type with two variants, Nil and Cons, and uses structural sharing so that prepend is an O(1) operation. By implementing map and filter with iterative loops instead of recursion, the library avoids StackOverflowError on large datasets while maintaining functional purity, and it is already positioned to benefit from Project Valhalla’s value types, which will make the nodes as memory‑dense as primitives. The author shares the full source on GitHub, highlights the thread‑safe, memory‑efficient design, and encourages developers to adopt the Sovereign List for local‑first, privacy‑centric applications that require persistent, immutable data structures.

Key changes

  • Sealed interface ImmutableList<T> permits Nil and Cons variants.
  • Nil is an empty record; Cons holds head and tail references.
  • prepend returns a new Cons node, achieving O(1) performance.
  • map and filter use iterative loops to avoid recursion and stack overflows.
  • Structural sharing allows multiple list versions to share nodes without copying.
  • The implementation is ready for Project Valhalla value types to reduce memory overhead.
  • Thread‑safe and memory‑efficient design suits local‑first, privacy‑centric apps.
  • Source code available on GitHub under devsatya/sovereign-list.

Affects

internal

Customer impact

Analyzing matches…

Ask about this story

Impact on an agency? Which customers? Compare historically Risks of waiting