DEV Community

Discussion on: Records in java

Collapse
 
khmarbaise profile image
Karl Heinz Marbaise

The idea of recors was not to reduce boilerplate code. The intention of records was to have a named data carrier... openjdk.org/jeps/395
The problem with annotations is currently that not many of libs have been upgraded accordingly..Furthermore

records are inherently immutable.

This is not correct... in depends on which kind of attributes you define... things like this:

public record Link(List<Node> nodes) { }

var nodes = new ArrayList<Node>();
nodes.add(new Node());

var link = new Link(nodes);

link.nodes().add(new Node());
Enter fullscreen mode Exit fullscreen mode

This will make clear the nodes() is not immutable...