Idea中开启assert断言
先打开相应的面板,有以下两种方式。
然后在VM栏里输入 -enableassertions 或者 -ea 就好了
然后编写程序试试
我的目录结构如下:(因为Main class那里要写类的全限定名, -ea的上一行)
代码:
1
2
3
4
5
6
7
|
public class AssertTest
{
public static void main(String[]
args) {
int a
= 10 ;
int b
= 20 ;
assert a
> b : "错误,a不大于b" ;
}
}
|
结果:
如果不写-ea,则程序继续执行,不检测assert断言,不会报异常.