/** * Simple examples test enable assertion feature in JDK1.4 * * @author Cherami 25/4/2002 **/
public class AssertExample2 {
public static void main(String[] args) { boolean assertEnable=false; assert assertEnable=true; if (assertEnable==false){ throw new RuntimeException("Assertions should be enable"); } }
}
假如我们不使用-ea参数运行上面的程序,则控制台将输出:
Exception in thread "main" java.lang.RuntimeException: Assertions should be enab le at AssertExample.main(AssertExample.java:14)本回答被网友采纳