title: Is there an beautiful way to assert pre-conditions in Java methods?
body: <p>A lot of my  functions have a whole load of validation code just below the declarations:</p>
  
  <pre><code>if ( ! (start &lt; end) ) {
      throw new IllegalStateException( "Start must be before end." );
      }
  </code></pre>
  
  <p>I'd like to precisly specify the valid ranges of certain inputs - for example a A > B,  C => 
   1 or str_d.length() > 0. </p>
  
  <p>Given that some of my functions have quite a lot of arguments which must be validated I can end up writing a lot of boiler-plate just to validate the pre-conditions. I'm writing a library which is mainly going to be used by non-technical developers, we've found that validating function inputs is the best way to help our users operate our API correctly. The sooner we raise an error the less work our customers will have to do.</p>
  
  <p>Is there a more elegant method to specify the pre-conditions, post-condtions (and possibly the invariant conditions) in my methods. </p>
  
  <p>A colleague told me about a feature of the Eiffel programming language which allows pre/post/invariant conditions to be described in very natural ways without repeating a lot of boilerplate code. Is there an add-on to the Java language which will allow me to use some of this magic? </p>