Annotation 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).

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Element Details