Assertions in Java
1 Overview
- Java Assertions Slides: [from Lehigh.edu (Java 1.4 but still good)]
PDF PPT
- Excerpts from http://www.javapractices.com/
- Assertions in general
- Assert use cases
- Force enabling of assertions
- Assert is for private arguments only
3 Java Programming With Assertions by Oracle.com
- Assertions are part of language definition. Not macro based.
- E1 is a boolean expressions. E2 is an expression
that has a value.
assert E1 ;
When the system runs the assertion, it evaluates E1
and if it is false throws an AssertionError
with no detail
message.
assert E1 : E2 ;
The AssertionError
constructor uses the string
value of Expression2 to generate a detailed message when E1 is
false.