My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

Contracts for Java enables you to annotate your code with contracts in the form of preconditions, postconditions and invariants.

These contract annotations are

  • easy to write and read,
  • and checked at runtime.

Annotating code with contracts helps you:

  • design,
  • document,
  • test, and
  • debug
your programs.

Here is a simple example of a Java class annotated with contracts:

interface Time {
  ...

  @Ensures({
    "result >= 0",
    "result <= 23"
  })
  int getHour();

  @Requires({
    "h >= 0",
    "h <= 23"
  })
  @Ensures("getHour() == h")
  void setHour(int h);

  ...
}

Here is what the contract for setHour regulates.

Obligation Benefit
Calling method Satisfy precondition; Make sure 'h' is neither too small nor too large. (From postcondition) getHour() returns h.
Called method Satisfy postcondition; Must make getHour() return h. (From precondition) May assume h is neither too small nor too large.

To use Cofoja you need to do the following two things:

The following provide more information about Cofoja:

Powered by Google Project Hosting