Package: groovy.contracts

## [Java] Annotation Type Invariant

- groovy.contracts.Invariant

-     @Documented
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.TYPE)
      @ClassInvariant
      @Repeatable(Invariants.class)
      @AnnotationProcessorImplementation(ClassInvariantAnnotationProcessor.class)
      public @interface Invariant

  Represents a class-invariant or a loop invariant.

  When applied to a class, defines assertions holding during the entire object's life-time. Class-invariants are verified at runtime at the following pointcuts:

  - after a constructor call
  - before a method call
  - after a method call

  When applied to a `for`, `while`, or `do-while` loop, defines a loop invariant that is asserted at the start of each iteration:

       int sum = 0
       @Invariant({ 0 <= i && i <= 4 })
       for (int i in 0..4) {
           sum += i
       }

  Whenever a class has a parent which itself specifies a class-invariant, that class-invariant expression is combined with the actual class's invariant (by using a logical AND).

  Since:
    4.0.0

- - ### Element Summary

    Required Element Summary
    Type | Name and Description
    --- | ---
    `Class` | `value` Returns the closure class that evaluates the invariant expression.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Element Detail

    - #### public Class value

      Returns the closure class that evaluates the invariant expression.

      Returns:
        the generated closure class backing the invariant