您的位置:首页 > 编程语言 > Java开发

Spring的断言工具类Assert的基本使用

2018-02-23 15:41 274 查看
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 clazz, Object obj, "clazz must be of type [clazz]")    -    obj必须能被正确造型成为clazz 指定的类
可以把if(判断){}改为断言
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: