Google announces cofoja – Contracts for Java

Google announced the new project cofoja (Contracts for Java) that is hosted on Google Code.
The project Website describes the project as follows:

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

With this functionality it’s possible to change the following lines

public int addTwo(int positiveValue) {
// check preconditions
if(positiveValue<1) {
throw new IllegalArgumentException();
}
return positiveValue+2;
}

to

@Requires({
"positiveValue >= 1"
})
public int addTwo(int positiveValue) {
return positiveValue+2;
}

Short URL for this post: https://wp.me/p4nxik-oM
This entry was posted in Java and Quality and tagged , , , , . Bookmark the permalink.

Leave a Reply