First, the basic knowledge
Assert can be used in Java to create assertions that assert that a condition should be true during the execution of a program. If the condition is false, a Assertionerror exception is thrown. Assertions are closed by default and are typically not used in the release code, and you do not need to remove assert statements from the published code.
Assertions can be used instead of judgment statements to simplify the inspection of common errors during development.
Second, the switch assertion
IntelliJ idea:
Edit configurations, VM options, fill-ea (enableassertions) or-da (disableassertions)
Iii. Use of assertions
classSolution {Static intval = 1; Static intget () {returnval--; } Public Static voidMain (string[] args) { for(inti = 0; I < 3; i++) assertGet () >= 0; //Exception in thread "main" Java.lang.AssertionError//At Solution.main (solution.java:10) }}View Code
Java notes: Assertions