Old
public record Person(String name,
List<String> pets) {
// Full canonical constructor
public Person(String name,
List<String> pets) {
Objects.requireNonNull(name);
this.name = name;
this.pets = List.copyOf(pets);
}
}
Modern
public record Person(String name,
List<String> pets) {
// Compact constructor
public Person {
Objects.requireNonNull(name);
pets = List.copyOf(pets);
}
}
hover to see modern →