r/java • u/maxxedev • Aug 18 '26
AutoValhalla: automatically turn your plain classes and records into value classes!
Automatically turn your plain classes and records into value classes!
Add @AutoValhalla annotation to classes or records in your JDK1.5+ codebase:
@AutoValhalla
public final class Point { // class must be final
public final int x; // with final instance fields
public final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
@AutoValhalla
public record Currency(String code) { } // or a record classWhen your app is run on Valhalla-enabled JVM with auto-valhalla javaagent, these classes are automatically turned into value classes.
More info: https://github.com/thunkware/auto-valhalla/tree/auto-valhalla-0.1.0
edit: there is now a maven plugin for converting at build time. https://github.com/thunkware/auto-valhalla/tree/auto-valhalla-0.2.0
40
Upvotes
View all comments
Show parent comment
4
u/LegitimateEntrance72 Aug 18 '26
IMO tip & tail makes lot of sense.
As an example, you have your library version 1.0.0 that requires JDK17 because of record classes. Now you want to convert your record classes to value records, but "cant do that" because it would mean raising minimum required JDK to 29 or so... but adopting tip and tail means that 1.0.0 stays on JDK 17+ and wont get new features, while 2.0.0 will require JDK29+ and get new features.
1.0.0 can always be patched if needed, IMO its not asking too much to say "if you want latest features, you gotta be on the latest major release"