A lot of my functions have a whole load of validation code just below the declarations:
if ( ! (start < end) ) {
throw new IllegalStateException( \"S
Check out the Cofoja project which provides contracts for Java through annotations. It provides Pre-/Postconditions and Invariants. Also in contrast to other Java implementations it correctly handles contracts defined in parent classes/interfaces. Contract evaluation can be enabled/disabled at runtime.
Here is a code snippet from their tutorial:
import com.google.java.contract.Invariant;
import com.google.java.contract.Requires;
@Invariant("size() >= 0")
interface Stack {
public int size();
@Requires("size() >= 1")
public T pop();
public void push(T obj);
}