foreword
Use the assert keyword to restrict parameter passing (check the validity of method parameters)
use
Assert.notNull(list,"集合不存在");
Format parameters: (assert booleanExpression, assert booleanExpression: messageExpression)
1. When the value of booleanExpression is true, the program continues to execute from the assertion statement;
2. When the value of booleanExpression is false, the program stops executing from the assertion statement and outputs messageException expression the value of the formula;
daily method
- Assert.notNull(Object object, “object is required”) - object is not null
- Assert.isTrue(Object object, “object must be true”) - object must be true
- Assert.notEmpty(Collection collection, “collection must not be empty”) - collection non-empty
- Assert.hasLength(String text, “text must be specified”) - character is not null and character length is not 0
- Assert.hasText(String text, “text must not be empty”) - text is not null and must contain at least one non-space character
- Assert.isInstanceOf(Class clazz, Object obj, “clazz must be of type [clazz]”) - obj must be able to be correctly cast as the class specified by clazz