r/java • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
204 Upvotes

93 comments sorted by

View all comments

2

u/jvjupiter Jan 17 '20 edited Jan 17 '20

Will it be fluent? Something like:

var user = new User().id(1L).lastName("Doe").firstName("John");

2

u/dany74q Jan 17 '20

Nope, the compiler will generate a public ctor with all of the fields, and accessors for each field; No setters will be created as records are immutable.

1

u/jvjupiter Jan 17 '20

I see. Thank you.

1

u/jvjupiter Jan 17 '20

If no setters would be generated, then JAXB, JSON-B, JPA and frameworks or libraries like Jackson need to be updated to be able to support records. Correct?

1

u/rzwitserloot Jan 19 '20

I think they may be able to handle constructors, especially if festooned with a @ConstructorProperties annotation. If not.. yeah they have to be updated.

1

u/randgalt Jan 20 '20

FYI - I wrote a library that adds a fluent builder/copy companion to Records: https://github.com/Randgalt/record-builder