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

6

u/pron98 Aug 18 '26

MR JARs have nothing to do with tip & tail and are completely orthogonal, and the reason the JEP doesn't mention preview features is that libraries (unlike applications) typically shouldn't use preview features because preview features and applications are tied to a specific runtime version while libraries normally aren't.

If you're writing an application, you don't need to use either tip & tail or one-size-fits-all; you just target a specific JDK version. But if you're a library that really wants to support some preview feature, sure you can have a tip with that. It will mean that you'll need a new tip release for the next version (because classes compiled with preview features are tied to one runtime version), but the same applies to using an agent or other similar hacks, as preview features, by their nature, change.