How to get started with Valhalla Early Access builds. Installing and using with Maven.
https://openjdk.org/projects/valhalla/early-access
https://jdk.java.net/valhalla/
mkdir -p ~/localjdk
mv ~/Downloads/openjdk-* ~/localjdkcd ~/localjdk
tar -xvf openjdk-*.tar.gzOn macOS, after expanding the tar.gz archive, you may need to remove the quarantine attribute from the bits before commands can be executed.
xattr -d com.apple.quarantine ./jdk-23.jdkmv jdk-23.jdk valhalla-23.jdk# the full path to the jdk is:
echo $(realpath valhalla-23.jdk/Contents/Home)
# install it to sdkman
sdk install java 23.ea.valhalla $(realpath valhalla-23.jdk/Contents/Home)
# check it ...
sdk use java 23.ea.valhalla
java -version❯ java -version
openjdk version "23-valhalla" 2024-09-17
OpenJDK Runtime Environment (build 23-valhalla+1-90)
OpenJDK 64-Bit Server VM (build 23-valhalla+1-90, mixed mode, sharing)
# remove the tarball
rm ~/localjdk/openjdk-23-valhalla+1-90_macos-aarch64_bin.tar.gz# uninstall it from sdkman
sdk uninstall java 23.ea.valhallaEnable preview features in the compiler plugin, surefire, failsafe, and javadoc plugin.
<properties>
<!-- surefire and failsafe -->
<argLine>--enable-preview</argLine>
<!-- compiler plugin -->
<maven.compiler.release>23</maven.compiler.release>
<maven.compiler.enablePreview>true</maven.compiler.enablePreview>
</properties> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalOptions>--enable-preview</additionalOptions> <!-- Valhalla -->
</configuration>
</plugin>If using maven plugins that run during the build these also might need to enable preview features.
Create a file in the root of the project called .mvn/jvm.config and add the
following line into that file:
--enable-previewMost record types are good candidates for value classes.
public value class MyRecord(String name, int age) {}value class MyValueClass {
// All fields are final
private /*final*/ OtherThing dependency;
MyValueClass(OtherThing dependency) {
this.dependency = dependency;
}
...
}All fields are final and no "Identity" so:
- All fields are final
- No use of
synchronized - No use of
Object.wait() - No use of
Object.notify() - the == operator compares value class instances according to their field values, without regard to when or where they were created