Make all fields in Java Immutable Nullable

321 views Asked by At
@Immutable
@Modifiable
public interface Record {

    String id();

    String fName();

    String lName();

    String mName();
}

All the fields in Record can be Nullable. One way for me to make these fields Nullable is to add @Nullable annotation on top of each field. Like this:

@Nullable
String mName()

Is there a way for me to specify at the interface level(through some annotation) that all fields can be null?

1

There are 1 answers

0
Mohamed Gara On

I used the following config to disable null check in builder and with methods:

@Value.Style(
  validationMethod = Value.Style.ValidationMethod.NONE,
)

The following quote is the the ValidationMethod.NONE javadoc description:

Disables null and mandatory attribute checks. Any missing primitives will be initialized to their zero-based values: false, 0, '\0'. Object references will be nulls. Any optional, default and collection attributes will be initialized with their appropriate default values regardless of this validation setting.