DescriptionContracts is a invocation validation framework for Java interfaces. It follows the principle of Design by contract via Java interface annotations. Contracts provides basic integration to Spring and Guice based Dependency injection usage. The JSR-305 effort is similar, and JSR-305 annotations will be used instead of proprietary ones in coming releases. ExamplesExample : @Contracts public interface SomeService { void mandatoryArgs(Object arg1, Object arg2); void nonEmptArg(@NotEmpty arg); void optionalArg(@Optional arg); @NotEmpty List nonEmptyReturn(); @Optional Object optionalReturn(); @Require("!args.isEmpty()") // not yet implemented void methodWithPrecondition(List args); @Ensure("return != null") // not yet implemented Object methodWithPostCondition(); } |
In a nutshell
|
Add Comment