11.10assert keyword

assert keyword, its main function is to assert, assert that after the implementation of the program refers to a row, the result must be the expected result
Example: Using observation assertions

package cn.mldn.demo;
public class JavaDemo {
	public static void main(String args[]) throws Exception {
		int x = 10;
		// 中间可能会经过许多条程序语句,导致变量x的内容发生改变
		assert x == 100 : "x的内容不是100";
		System.out.println(x);
	}
}

启用affirm:
Java -Ea Cn.Mldn.Demo.JavaDemo

Published 161 original articles · won praise 9 · views 3078

Guess you like

Origin blog.csdn.net/ll_j_21/article/details/104755747