java 15 record as generated immutable implementation
See original GitHub issueHow about generating the immutable implementation of a given interface as a java 15 record
(JEP 359)?
This would allow all the benefits of records
to be combined with the greatness and ecosystem integration of immutables (in my case: mainly compatibility with mapstruct and openapi).
WDYT?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Create Immutable Value Objects using Java Record Classes
This is an Introduction to Java Record Classes. We will learn to use Java records to create Immutable data objects, or Value Objects....
Read more >Bruce Eckel on Java records - Oracle Blogs
Records automatically generate. Immutable fields; A canonical constructor; An accessor method for each element; The equals() method ...
Read more >Java Records - Evren Tan
Java Record is a new way to declare a class to pass immutable data. Records were first introduced in Java 14 but they...
Read more >Java 14 Record Keyword - Baeldung
In this tutorial, we'll look at the fundamentals of records, including their purpose, generated methods, and customization techniques.
Read more >Avoid Multithreading Bugs Using Immutable Java Records
In this example, we created a list of integers(integerList), added one element into it, and initialized the record class with this. Calling method...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, maybe what I really need is a builder for records. And thats already possible using
@Builder.Constructor
(https://immutables.github.io/factory.html)Thanks for the discussion!
I thought of something along the lines of:
Data object definition:
Record-style implementation, generated by immutables:
Usage, bean-style (these getters need to be generated by immutables to fulfill interface declarations):
The jackson json deserializer would use the builder in a similar way. The jackson json serializer would use the bean-style getters.
Usage, record-style (these ‘getters’ are generated by compiler):
I think the overall behaviour of the generated records are the same in comparison to created immutable classes.
Note the restrictions of records (https://openjdk.java.net/jeps/395#Rules-for-record-classes), that is why i would recommend to enable usage of records on an opt-in basis via
@Value.Immutable(record = true)
.