Companion code for the ankurm.com post "Top 40 Java Collections Interview Questions (HashMap Internals to Fail-Fast Iterators)". Verified against JDK 25's own HashMap source (TREEIFY_THRESHOLD=8, UNTREEIFY_THRESHOLD=6, MIN_TREEIFY_CAPACITY=64), with every claim backed by a committed docs/output/*.txt transcript from a real run. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
33 lines
1.2 KiB
Bash
Executable File
33 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Runs one named scenario and prints it to stdout (does not touch docs/output - use
|
|
# run-all.sh to regenerate the committed transcripts). Examples:
|
|
#
|
|
# ./scripts/run.sh add-opens-fail # reflection WITHOUT --add-opens (crashes on purpose)
|
|
# ./scripts/run.sh add-opens-ok # reflection WITH --add-opens
|
|
# ./scripts/run.sh treeify # run just the treeification test, verbose
|
|
# ./scripts/run.sh cme # run just the ConcurrentModificationException tests
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
scenario="${1:?usage: run.sh <add-opens-fail|add-opens-ok|treeify|cme|eqhash|bucket>}"
|
|
|
|
mvn -q -B compile
|
|
|
|
case "$scenario" in
|
|
add-opens-fail)
|
|
java -cp target/classes com.ankurm.interviewlab.collections.ReflectionAddOpensDemo ;;
|
|
add-opens-ok)
|
|
java --add-opens java.base/java.util=ALL-UNNAMED -cp target/classes \
|
|
com.ankurm.interviewlab.collections.ReflectionAddOpensDemo ;;
|
|
treeify)
|
|
mvn -B test -Dtest=TreeifyTriggerTest ;;
|
|
cme)
|
|
mvn -B test -Dtest=ConcurrentModificationTest ;;
|
|
eqhash)
|
|
mvn -B test -Dtest=EqualsHashCodeContractTest ;;
|
|
bucket)
|
|
mvn -B test -Dtest=BucketLayoutTest ;;
|
|
*)
|
|
echo "unknown scenario: $scenario" >&2; exit 1 ;;
|
|
esac
|