Package groovy.contracts

# Annotation Interface Modifies

@Documented @Retention(RUNTIME) @Target({CONSTRUCTOR,METHOD}) @Incubating @Repeatable(ModifiesConditions.class) public @interface Modifies
Declares the frame condition for a method: the set of fields and parameters that the method is allowed to modify. All other state is implicitly declared unchanged.

The closure value lists the modifiable targets as field references (`this.fieldName`) or parameter references (`paramName`). Multiple targets can be specified using a list:

       @Modifies({ this.items })
       void addItem(Item item) { ... }

       @Modifies({ [this.items, this.count] })
       void addAndCount(Item item) { ... }

Multiple `@Modifies` annotations can also be used (via `Repeatable`):

       @Modifies({ this.items })
       @Modifies({ this.count })
       void addAndCount(Item item) { ... }

When both `@Modifies` and `Ensures` are present on a method, the `old` variable in the postcondition may only reference fields declared in `@Modifies`. A compile error is reported otherwise.

`@Modifies` does not generate runtime assertion code. It serves as a specification for humans and tools (including AI) to reason about method behavior.

Since:
  6.0.0
See Also:
  - `Ensures`
  - `Requires`

- ## Required Element Summary

  Required Elements
  Modifier and Type
  Required Element
  Description
  `Class`
  `value`
  Returns the closure class that lists the locations the annotated member may mutate.

- ## Element Details

  - ### value

    Class value
    Returns the closure class that lists the locations the annotated member may mutate.
    Returns:
      the generated closure class backing the frame-condition expression