Unfortunately, we have no mechanism in place to make that happen. You may want to checkout iContract , which is a Java Design by Contract system from Reliable Systems that overcomes some of the limitations of this simple approach. Jar File Example stack class with assertions. The Java software is made available under the LGPL license. Things to Remember Keep these things in mind when developing your contracts.
Queries generally have no precondition.
It should be legal to ask for the capacity of a stack at any time. Exceptions would be queries on attributes that only exist when the object is in particular states. For example, asking for the file name of a file object might only be valid if the file is open. Don't include fine print. In other words, don't require something that the client cannot determine.