An assertion is a statement containing a
boolean expression. If the assertion is enabled
as specified by the Java Language Specification, Third Edition,
an evaluation of the assertion causes evaluation of the
boolean expression and an error is reported if the expression
evaluates to false
. If an optional second expression
exists, the error message is based on the evaluation of this expression.
If the assertion is disabled, evaluation of the assertion has
no effect whatsoever.
Assert Statement | |||||
---|---|---|---|---|---|
|
It is a compile-time error if the first expression does not have
type boolean
or if the optional second expression
after the colon is void
. The evaluation of an
assert
is performed as specified by the
Java Language Specification, Third Edition.