打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
spring源码之

org.springframework.util.Assert
Assert翻译为中文为"断言".用过JUNIT的应该都知道这个概念了.
就是断定某一个实际的值就为自己预期想得到的,如果不一样就抛出异常.
Assert经常用于:
1.判断METHOD的参数是否属于正常值.
2.JUNIT中使用.

我发现SPRING1.2.6里面有BUG
请看:
org.springframework.core.io.support.EncodedResource中
public EncodedResource(Resource resource, String encoding) {
  Assert.notNull("Resource is required");
  this.resource = resource;
  this.encoding = encoding;
}

Assert.notNull("Resource is required");
这句应该为
Assert.notNull(resource,"Resource is required");
不然resource都没传过来,还断什么言啊,呵呵.

------------------------------------------------------------------------
上面是在网上看到了,但是我进入spring里面看了一下源码,如下:
/**
* Assert that an object is not <code>null</code> .
* <pre class="code">Assert.notNull(clazz, "The class must not be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is <code>null</code>
*/
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
该函数的意思是传入的object必须不能为空。如果为空就抛出异常。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
spring源码关于循环引用的笔记
CSocket对象不能在线程之间传递
Spring Roo: Saving/Retreving BLOB object in Spring Roo
Spring Boot 实现各种参数校验,非常实用!
Spring的Assert工具类的用法
【初探Spring】------Spring IOC(三):初始化过程---Resource定位
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服