- Force types to be explicit about the null-status (nullable or non-null) of all enclosed constructors, fields and methods
- In Java, the type system doesn't distinguish between nullable and non-null references,
so It's recommended to use null-status annotations
@NonNullor@Nullableannotations. this library forces any type annotated with@ExplicitNullStatusto use the null-status annotations or it will fail the build
@ExplicitNullStatus // => @NonNull @Nullable are required
public class User {
@NonNull
private String email;
@Nullable
private String avatar;
...
}@ExplicitNullStatus // => @NonNull @Nullable are required
public class User {
private String email; // => compile-time error
@Nullable
private String avatar;
...
}- you can suppress the null-status-check using
@Ignoreon the ignore element or@IgnoreConstructors,@IgnoreFields, and@IgnoreMethodson a type to ignore multiple elements.
@ExplicitNullStatus // => @NonNull @Nullable are required
public class User {
@Ignore
private String email; // => will be ignored
@Nullable
private String avatar;
...
}@ExplicitNullStatus // => @NonNull @Nullable are required
@IgnoreFields
public class User {
private String email; // => will be ignored
@Nullable
private String avatar;
...
}- Add it in your root build.gradle:
repositories {
maven { url 'https://jitpack.io' }
}- Add it in app build.gradle:
dependencies {
annotationProcessor 'com.github.AmrElmasry.explicit-null-status:explicit-null-status-compiler:1.0.0-beta4'
compile 'com.github.AmrElmasry.explicit-null-status:explicit-null-status-annotations:1.0.0-beta4'
} - check here to show the full list