Java 14 带来了记录,这是在许多函数式语言中看到的一个很好的补充:
爪哇:
public record Vehicle(String brand, String licensePlate) {}
毫升:
type Vehicle =
{
Brand : string
LicensePlate : string
}
在 ML 语言中,可以通过创建一个更改了一些值的副本来“更新”记录:
let u =
{
Brand = "Subaru"
LicensePlate = "ABC-DEFG"
}
let v =
{
u with
LicensePlate = "LMN-OPQR"
}
// Same as:
let v =
{
Brand = u.Brand
LicensePlate = "LMN-OPQR"
}
这在 Java 14 中可能吗?