Simple function to switch between multiple Java versions

Recently we have started upgrade our java applications to start using Java 8.  Wanted to quick and easy way to switch between different versions of Java.

If I was using a debian variant of Linux(Ubuntu/Mint etc.), I could have used

sudo update-alternatives --config java

But am using a Mac, hence wrote this …

jvm() {
 export JAVA_HOME=`/usr/libexec/java_home -v "$1"`
 java -version