Assertion:
public static void main(String[] args) { int x = 10; assert x==100:"assertion failed!"; }
How to determine assertion is enabled or not?
boolean isEnable=false; assert isEnable = true; if(isEnable){ throw new RuntimeException("Assertion shoule be enable!"); }
This is a bad assertion, because it change the value, If assertion is enabled, isEnable will be set to true.
Debug/Run configurations > VM arguments: add “-ea” to enable it or “-da” to disable assertion.
should not used for validate parameter in public method: because anyone can use public method, and can not make sure assertion is enabled or not;
About Exceptions in Java <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.