Code inspired by re-reading Effective Java.