Basics, failure semantics on 26 vs 27, lazy collections, API across 25/26/27, preview-flag traps and a JMH read-path benchmark (jars fetched and sha1-checked, not committed). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
18 lines
1.3 KiB
Markdown
18 lines
1.3 KiB
Markdown
# lazy-constants — Lazy Constants (JEP 531, third preview in JDK 27)
|
|
|
|
Companion code for the ankurm.com article **Lazy Constants in JDK 27 (JEP 531): Replacing Double-Checked Locking**. The explanation lives in the article;
|
|
this folder holds the runnable sources and the transcripts they produced.
|
|
|
|
```bash
|
|
JDK25=/path/to/jdk-25 JDK26=/path/to/jdk-26 JDK27=/path/to/jdk-27 [JDK21=/path/to/jdk-21] ./run.sh # regenerates output/*.txt
|
|
RUN_JMH=0 ./run.sh # skip the 3-minute benchmark
|
|
```
|
|
|
|
- `src/` — `OldWays` (holder idiom and double-checked locking, plain Java), `Basics`, `ToStringStates`, `Service`, `Failures`, `LazyCollections` (JDK 27, `--enable-preview`), `StableValue25` (the JDK 25 API).
|
|
- `broken/` — code that fails to compile on purpose: the old `StableValue` name, the two methods removed in 27, no `--enable-preview`, a `set` that does not exist.
|
|
- `jmh/` — a JMH 1.37 benchmark of the read path. `./jmh/fetch.sh` downloads the jars from Maven Central and checks their sha1; they are not committed. `./jmh/run-jmh.sh` writes `output/07-jmh.txt`.
|
|
|
|
Everything except the JMH numbers is byte-stable. The JMH numbers are machine dependent: treat them as shape, not results.
|
|
|
|
Tested on Temurin 25.0.4.1+1, 26.0.2.1+1 and 27+35, and OpenJDK 21.0.10 for the plain-Java baseline.
|