Java Reference
In-Depth Information
D.5
Assertions
Assertion statements are primarily used as a testing tool during program development rather
than in production code. There are two forms of assert statement:
assert boolean-expression ;
assert boolean-expression : expression ;
Examples:
assert getDetails(key) != null ;
assert expected == actual:
"Actual value: " + actual +
" does not match expected value: " + expected;
If the assertion expression evaluates to false , then an AssertionError will be thrown.
A compiler option allows assertion statements to be rendered inactive in production code with-
out having to remove them from the program source.
Search WWH ::




Custom Search