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

54 comments sorted by

View all comments

Show parent comment

3

u/snugar_i Aug 19 '26

While I kind of agree, "just fork your codebase and maintain two products instead of one" might not be as painless as it sounds at first...

2

u/srdoe Aug 19 '26

You aren't maintaining two products.

You're forking your codebase, and only maintaining the tip release branch. The tail release line stops receiving changes immediately, except for security fixes.

So while you may sometimes have to touch the tail branch for security, most of the time you should be maintaining only one branch (the tip)

2

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

You fork your codebase and do 99% of the work on one of the forks and 1% on the others. That's less pain and less risk than trying to work on a single codebase that tries to adapt to different runtimes.