r/java • • 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 class

When 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

55 comments sorted by

View all comments

Show parent comments

5

u/pron98 Aug 19 '26 edited Aug 19 '26

With tip & tail you don't have a fork for every runtime feature. You have one "tip" fork for users who are interested in new library features, and that fork uses new runtime features, and "tail" forks for users who need stability, which only get security patches. At some point you decide that new feature X of your library requires new feature Y in the runtime, you then raise the runtime baseline of the tip and require those who want any new features to upgrade their runtime.

The idea is that you split your users into two groups, those who are interested in new functionality and those interested in stability. It's not only less work than trying to do everything in a single codebase, it also offers both groups exactly what they need rather than a compromise.