Which Java keyword declares a shallowly immutable data carrier class?
Correct answer A. record
Explanation
A record declaration, standard since Java 16, names its components in a header, and the compiler generates private final fields, a canonical constructor, accessors, equals, hashCode and toString. It is only shallowly immutable, because a component holding a mutable object can still be changed internally. The words data, struct and tuple are not Java class declarations.
Answer checked How we write and check questions
Discussion