Assertion checks a Boolean expression. A correct program must ensure that the value of this Boolean expression is true. If this value is false, the system will throw assertionerror.
Syntax:
Assert expression1;
Assert expression1: expression2;
Expression1 indicates a Boolean value or expression or a method that can return a Boolean value. expression2 is an object. Generally, a written string is contained in assertionerror, prompting you
For example:
Assert 1! = 1: "--> error! <--";
The running will print:
Exception in thread "Main" Java. Lang. assertionerror: --> error! <--
At com. auscend. kenth. Student. Information. util. Test. Main (test. Java: 5)
To support assert, You need to enable this function at runtime. Java-ea indicates enabling-da indicates disabling the full name "-enableassertions" and "-disenableassertions" indicates disabling the function during release during development and debugging.
Assert helps developers find program error states to improve program robustness, and should not be part of the normal running logic of the program.
Copy search
Copy search