Annotation Interface Contract.InRange

Enclosing class:
Contract

@API(status=MAINTAINED) @Contract @Target({PARAMETER,METHOD,FIELD,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented public static @interface Contract.InRange
Requires a numeric value to fall within the configured range.

Supported values are primitive numeric values, numeric wrapper types, BigDecimal, and BigInteger. A null object value is ignored and therefore passes.

Both range endpoints are inclusive by default. Use minInclusive() and maxInclusive() to make either bound exclusive.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    long
    Upper numeric bound.
    long
    Lower numeric bound.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether the upper bound is inclusive.
    Custom violation description.
    boolean
    Whether the lower bound is inclusive.
  • Element Details

    • min

      long min
      Lower numeric bound.
      Returns:
      the minimum allowed value
    • max

      long max
      Upper numeric bound.
      Returns:
      the maximum allowed value
    • minInclusive

      boolean minInclusive
      Whether the lower bound is inclusive.
      Returns:
      true when values equal to min() pass
      Default:
      true
    • maxInclusive

      boolean maxInclusive
      Whether the upper bound is inclusive.
      Returns:
      true when values equal to max() pass
      Default:
      true
    • message

      String message
      Custom violation description.

      When non-empty, this text replaces the generated contract description while preserving location details, exception type, and masking behavior.

      Returns:
      the custom violation description, or an empty string to use the generated description
      Default:
      ""