14.10. The assert Statement
An assertion is an assert
statement containing a boolean expression. An assertion is either enabled or disabled. If the assertion is enabled, execution of the assertion causes evaluation of the boolean expression and an error is reported if the expression evaluates to false
. If the assertion is disabled, execution of the assertion has no effect whatsoever.
AssertStatement: assert
Expression1 ;
assert
Expression1 :
Expression2 ;
It is a compile-time error if Expression1 does not have type boolean
or Boolean
.
In the second form of the assert
statement, it is a compile-time error if Expression2 is void
(§15.1).
An assert
statement that is executed after its class has completed initialization is enabled if and only ...
Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.