断言表达式


断言表达式

assert 关键字,可以判断一个条件,如果不成立则会抛出 AssertionError 错误

也可以在判断的表达式后面加 : 来显示一个message,即错误信息

main(){
	int a = 10;
	assert a > 10 : "a此时不大于10";
}

一般用于测试,正常程序不会用到


Author: havenochoice
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source havenochoice !
评论
  TOC