Annotation Interface Contract


@API(status=MAINTAINED) @Target(ANNOTATION_TYPE) @Retention(RUNTIME) @Documented public @interface Contract
Namespace and meta-annotation for declarative Java contracts.

Built-in contract annotations are nested under this type so a single import gives callers access to declarations such as @Contract.Positive and @Contract.Pattern. Custom composed annotations can be marked with @Contract and may combine built-in annotations.

Built-in semantic contracts are supported on parameters, methods, fields, and annotation types. Parameter annotations are enforced as preconditions, method annotations are enforced as postconditions on non-void return values, field annotations are metadata for reuse and tools such as Lombok, and annotation-type annotations allow custom composed contracts.

Semantic contracts are null-safe for object values: when a supported value is null, the contract is skipped and therefore passes. Nullness is intentionally outside this framework; use dedicated nullness tooling for required/non-null contracts.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Requires a numeric value to fall within the configured range.
    static @interface 
    Marks a value as confidential for generated violation messages.
    static @interface 
    Requires a numeric value to be less than zero.
    static @interface 
    Requires a numeric value to be greater than or equal to zero.
    static @interface 
    Requires a numeric value to be less than or equal to zero.
    static @interface 
    Requires a character sequence to contain non-whitespace content when non-null.
    static @interface 
    Requires a character sequence, collection, map, or array value to be non-empty when non-null.
    static @interface 
    Requires a character sequence to match the configured regular expression when non-null.
    static @interface 
    Requires a numeric value to be greater than zero.
    static @interface 
    Requires a character sequence, collection, map, or array value size to be in range when non-null.