An assertion is a statement containing a boolean expression that the programmer believes will be true every time the statement is executed when the program runs.
For example,
int i = in.read();
assert i >= -1 && i <= 256;
If an assertion fails at runtime an AssertionError
is thrown.
Typically, assertion-checking is enabled during program development and testing, and disabled for deployment. Therefore assertions should not have side effects.
Assertions should not be used to check arguments to public methods; (instead regular logic should be used and an exception thrown if there's a problem) but of course this is exactly what programmers will use them for.
Introduces a number of backwards compatibility issues because of the
new keyword and ClassLoader
changes required to support assertions.
Possibly included in Java 1.4; RFE "fixed in a non-public release"
http://java.sun.com/aboutJava/communityprocess/review/jsr041/publicDraft.html