Spring中的Assert断言经常使用方法及做用

概念

Assert翻译为中文为"断言",就是判定某一个实际的值就为本身预期想获得的,若是不同就抛出异常。ui

方法及做用

Assert.notNull(Object object,"object is required");  // 对象非空
Assert.isTrue(Object object,"object must be true");  // 对象必须为true
Assert.notEmpty(Collection collection,"collection must not be empty");  // 集合不能为空
Assert.hasLength(String text,"text must be specified");  // 字符不为null且字符长度不为0
Assert.hasText(String text,"text must not be empty");  // text不为null且必须至少包含一个非空的字符
Assert.isInstanceOf(Class class, Object object,"class must be of type[class]");  // object必须为class指定的类
相关文章
相关标签/搜索