Things I don't like about java records
- record is final so it
- can't be used in inheritance
- can't be mocked in unit tests
- doesn't support builder pattern and as the number of fields grows Lombok's
@Builder
becomes preferable- although it seems to be possible to use Lombok's
@Builder
with java record
- although it seems to be possible to use Lombok's
I don't see any major advantages with using record other than its immutable nature.
Java record
import lombok.Builder;
@Builder
record FooRecord(
String name,
String city,
String zip) {
}
Java class
import lombok.Builder;
import lombok.Data;
@Data
@Builder
class FooData {
String name;
String city;
String zip;
}