What are some real life examples to understand the key role of the Java assert
keyword?
What Are Assertions in Java and When to Use Them
assertionjava
assertionjava
What are some real life examples to understand the key role of the Java assert
keyword?
Best Answer
Assertions (by way of the
assert
keyword) were added in Java 1.4. They are used to verify the correctness of an invariant in the code. They should never be triggered in production code, and are indicative of a bug or misuse of a code path. They can be activated at run-time by way of the-ea
option on thejava
command, but are not turned on by default.An example: