断言在默认情况下是关闭的,要在编译时启用断言,
只要给eclipse相应的jre中增加一个参数即可
可以根据以下代码判断断言是否打开:
public class AssertExampleTwo{
public static void main(String args[]){
boolean isEnable=false;
//...
assert isEnable=true;//如果未打开,就不会执行该语句
if(isEnable==false){
throw new RuntimeException("Assertion shoule be enable!");
}
}
}
转载于:https://my.oschina.net/beanGo/blog/184282