Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Generate composite records #3718

Open
depsypher opened this issue Aug 8, 2024 · 1 comment
Open

[FEATURE] Generate composite records #3718

depsypher opened this issue Aug 8, 2024 · 1 comment

Comments

@depsypher
Copy link

It would be cool if Lombok could make up for the inability to extend records in Java by generating a composite record from another record you specify.

Plain Java:

record Vehicle(int topSpeed, int passengers) {
}

record Bike(int topSpeed, int passengers, int wheels) {
    public Bike(Vehicle vehicle, int wheels) {
        this(vehicle.topSpeed(), vehicle.passengers(), wheels);
    }
}

Lombok:

@ExtendsRecord(Vehicle.class)	// generates the Bike record above
record Bike(int wheels) {
}

// can create specifying all fields
Bike bike = new Bike(50, 1, 2);

// or by passing in a "base" record along with the extra parameters
Vehicle twoSeater = new Vehicle(50, 2);
Bike tandem = new Bike(twoSeater, 2);
@abdelhak-zaaim
Copy link

its looks a great idea,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants