immutable: List.of vs unmodifiableList vs copyOf - null handling, views vs copies, JMH wrap/copy overhead, a Guava comparison, and the record defensive-copy trap

This commit is contained in:
2026-10-01 11:32:13 +00:00
parent 64de44fa65
commit 2eaa464bad
18 changed files with 731 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
mvn -q -B compile
GUAVA_JAR="$(find "$HOME/.m2" -name 'guava-*.jar' ! -name '*sources*' | head -1)"
CP="target/classes:${GUAVA_JAR}"
java -cp "$CP" com.ankurm.immutable.NullHandlingDemo 2>&1 \
| grep -vE 'JAVA_TOOL_OPTIONS|^WARNING' > output/01-null-handling.txt
java -cp "$CP" com.ankurm.immutable.ViewsVsCopiesDemo 2>&1 \
| grep -vE 'JAVA_TOOL_OPTIONS|^WARNING' > output/02-views-vs-copies.txt
java -cp "$CP" com.ankurm.immutable.GuavaComparisonDemo 2>&1 \
| grep -vE 'JAVA_TOOL_OPTIONS|^WARNING' > output/03-guava-comparison.txt
java -cp "$CP" com.ankurm.immutable.DefensiveCopyRecordDemo 2>&1 \
| grep -vE 'JAVA_TOOL_OPTIONS|^WARNING' > output/04-defensive-copy-record.txt
mvn -q -B package -DskipTests
java -jar target/benchmarks.jar -rf text -rff output/05-jmh-raw.txt
mvn -q -B test
cp target/surefire-reports/com.ankurm.immutable.ImmutableCollectionsTest.txt output/06-tests.txt
echo "Regenerated output/01-06. Note: 05-jmh-raw.txt numbers are indicative - this sandbox is shared."