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

Support for Java 14+ records #1484

Open
y2k-shubham opened this issue Sep 16, 2023 · 2 comments
Open

Support for Java 14+ records #1484

y2k-shubham opened this issue Sep 16, 2023 · 2 comments

Comments

@y2k-shubham
Copy link

y2k-shubham commented Sep 16, 2023

  • It might sound counter-intuitive given that even though Java records are immutable by their very definition, I want to use @Value.Immutable annotation with them. That's because one delightful feature that @Value.Immutable annotation provides for conventional Java interfaces and abstract classes is the builder-methods that enable graceful object construction, especially DTOs within multiple fields including several Optionals
  • Presently to use builder-pattern with Java records, we have 3 paths as per this article
    1. Hand-written Builder class nested within Java record class
    2. Lombok (no, please no)
    3. This small RecordBuilder library of which I'm sceptical as to how long would it be supported by community (plus it also offers several customizations around pure / simple builders that i'm not too keen about & don't want those unnecessary loopholes in my project)

So then are there any plans to support @Value.Immutable annotation for Java records and by when?

@elucash
Copy link
Member

elucash commented Sep 22, 2023

We're planning to add quite full support for records. Most probably it will be Immutables 3 . But there's the way now, using @Builder.Constructor annotation on a compact constructor. @Builder.Constructor was originally was created to support free-form objects/pojo constructors.
See #1285 for the details, in particular, here's the example (#1285 (comment))

record Uio(
  int x,
  String b,
  boolean z
) {
  @Builder.Constructor Uio {}
}

var b = new UioBuilder()
  .x(4)
  .b("xx")
  .z(true)
  .build();

@bmarwell
Copy link

Can't wait to see this in a release!

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

No branches or pull requests

3 participants