| For example, * tuples (complex numbers, points, dimensions, colors, IP addresses), * database query results, * stateless beans for DI frameworks where it cuts down on the verbosity of using constructor injection (actually a slight misuse) * composite natural keys in database modeling The immutability can help to enforce API contracts and proper service layering. A common problem in legacy code is modules communicating with each other by modifying objects that were passed as arguments. Eventually, Project Valhalla will introduce the possibility to declare records as primitive, which will also reduce the overhead of Wither methods. Edit: Building web APIs should also benefit from records because the argument and result types are only supposed to be created and read, not modified. |