I've been thinking about creating a Java framework that would allow programmers to specify invariants (pre- and post-conditions) on interfaces. The purpose would be to make code more robust and reduce the number of unit tests that would need to be written for different implementations of the same interface.
I envisage creating some way of annotating methods with invariants that the programmer would also write. E.G.
interface Sort {
int [] sort(int [] nums);
}
would be decorated with an annotation to ensure that any implementations return a sorted list. This annotation would be linked to a unit test that could be run at compile time against any implementation.
Is this a crazy idea or would this be useful to the wider programming community?