Given a simple class with a final field, such as a String (see example below) or Spring dependencies, is a good idea to use a Java 14 record to make it more concise and possibly remove annotation processors such as Lombok?
According to the JEP describing records, "Records make the semantic claim of being simple, transparent holders for their data".
Obviously, a generic class with only final fields, is not exactly a transparent holder for its data, and when using a record, its final variables are exposed, which may not be desirable. However, in many cases it is probably not a major problem.
Therefore, is this "enough" to consider it an "abuse" of this language feature? Or are there any other, less obvious drawbacks?
@RequiredArgsConstructor // or an explicit constructor when not using lombok
class AudienceValidator implements OAuth2TokenValidator<Jwt> {
private final String audience;
public OAuth2TokenValidatorResult validate(Jwt jwt) {
// validate
}
}
record AudienceValidator(String audience) implements OAuth2TokenValidator<Jwt> {
public OAuth2TokenValidatorResult validate(Jwt jwt) {
// validate
}
}