Package io.micronaut.core.annotation
Annotation Interface NullMarked
@Documented
@Target({MODULE,PACKAGE,TYPE,METHOD,CONSTRUCTOR})
@Retention(RUNTIME)
public @interface NullMarked
Marks the annotated declaration and all code transitively enclosed by it as null-marked:
within that scope, type usages are non-null by default unless explicitly annotated as
@Nullable
.
This annotation is intentionally similar in purpose and semantics to
org.jspecify.annotations.NullMarked
. It provides an opt-in, "non-null by default" mode so
you don't have to repeat a non-null annotation on every type usage.
Where it can be used:
- Module declarations (before the
module
keyword) - Packages (via
package-info.java
) - Types (classes, interfaces, records, enums)
- Methods
- Constructors
Behavior notes:
- The effect applies transitively to enclosed declarations.
- Elements can opt out by explicitly using
@Nullable
on type usages, or with a counterpart such as@NullUnmarked
if available. - Some language constructs (e.g., wildcards and type variables) may need explicit nullness annotations to express intent clearly.
- Author:
- Denis Stepanov