首页 > 编程语言 > 详细

spring断言使用

时间:2017-06-27 19:21:49      阅读:348      评论:0      收藏:0      [点我收藏+]

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

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     }

 

spring断言使用

原文:http://www.cnblogs.com/hunt/p/7086533.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!