Code requires Java 11+.
The source code from the third edition of Effective Java, with minor additions as necessary to make it runnable.