A lot of my functions have a whole load of validation code just below the declarations:
if ( ! (start < end) ) { throw new IllegalStateException( \"S
Aspect oriented programming can be used for such a problem. Method calls can be intercepted checking for the invariant. Pointcuts and advices are configured in a declarative way. Spring and Guice make usage of AOP straightforward.
Here's an example in Guice.