spring断言使用

断言就是断定某一个实际的值为自己预期想得到的,如果不一样就抛出异常。

Assert经常用于:

1.判断method的参数是否属于正常值。
2.juit中使用。

 1 import org.springframework.util.Assert;
 2 
 3 /**
 4  * Created by hunt on 2017/6/27.
 5  */
 6 public class AssertTest {
 7     public static void main(String[] args) {
 8         String name = null;
 9         Assert.notNull(name,"name不能为空");
10     }
11 }

 

Assert.notNull源码:

1     public static void notNull(Object object, String message) {
2         if (object == null) {
3             throw new IllegalArgumentException(message);
4         }
5     }

 

posted on 2017-06-27 18:07  默默红尘  阅读(772)  评论(0编辑  收藏  举报

导航