Asserting

suggest change

Versions

[{“Name”:“Java SE 1.4”,“GroupName”:null},{“Name”:“Java SE 5”,“GroupName”:null},{“Name”:“Java SE 6”,“GroupName”:null},{“Name”:“Java SE 7”,“GroupName”:null},{“Name”:“Java SE 8”,“GroupName”:null},{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]

Syntax

Parameters

Parameter | Details | ——— | —–– | expression1 | The assertion statement throws an AssertionError if this expression evaluates to false. | expression2 | Optional. When used, AssertionErrors thrown by the assert statement have this message. |

Remarks

By default, assertions are disabled at runtime.

To enable assertions, you must run java with -ea flag.

java -ea com.example.AssertionExample

Assertions are statements that will throw an error if their expression evaluates to false. Assertions should only be used to test code; they should never be used in production.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Asserting:
* Asserting

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
40 Asserting
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap