I'm using macOS, when homebrew updates the JDK I have to manually update the $JAVA_HOME path in .zshrc since it uses the version number in its path, just replace the version number to a newer one like
/usr/local/Cellar/openjdk@11/11.0.14/libexec/openjdk.jdk/Contents/Home
to
/usr/local/Cellar/openjdk@11/11.0.16/libexec/openjdk.jdk/Contents/Home
As you can see there is just a difference in version numbers, other directory names are still the same. Is there any way to automatically update JAVA_HOME to the path that Homebrew just updated?