![](https://camo.githubusercontent.com/c255218bd2390ecb0e4eb49abeb677a4f1dff6ce1602166231499b545881b7fd/68747470733a2f2f6a69747061636b2e696f2f762f416d72456c6d617372792f6578706c696369742d6e756c6c2d7374617475732e737667)
- 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
@NonNull
or @Nullable
annotations.
this library forces any type annotated with @ExplicitNullStatus
to 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
@Ignore
on the ignore element or @IgnoreConstructors
, @IgnoreFields
, and @IgnoreMethods
on 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