Assert和Enumeration的用法
2015-12-15 10:24
477 查看
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 isrequired");
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 mustnot 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必须不能为空。如果为空就抛出异常。
Enumeration(列举)
public interface Enumeration<E>实现 Enumeration 接口的对象,它生成一系列元素,一次生成一个。连续调用 nextElement 方法将返回一系列的连续元素。
例如,要输出 Vector<E> v 的所有元素,可使用以下方法:
for (Enumeration<E> e = v.elements();e.hasMoreElements();)
System.out.println(e.nextElement());
这些方法主要通过向量的元素、哈希表的键以及哈希表中的值进行枚举。枚举也用于将输入流指定到 SequenceInputStream 中。
注:此接口的功能与 Iterator 接口的功能是重复的。此外,Iterator接口添加了一个可选的移除操作,并使用较短的方法名。新的实现应该优先考虑使用 Iterator 接口而不是 Enumeration 接口。
有两个方法:
hasMoreElements() 测试此枚举是否包含更多的元素。
nextElement() 如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。
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 isrequired");
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 mustnot 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必须不能为空。如果为空就抛出异常。
Enumeration(列举)
public interface Enumeration<E>实现 Enumeration 接口的对象,它生成一系列元素,一次生成一个。连续调用 nextElement 方法将返回一系列的连续元素。
例如,要输出 Vector<E> v 的所有元素,可使用以下方法:
for (Enumeration<E> e = v.elements();e.hasMoreElements();)
System.out.println(e.nextElement());
这些方法主要通过向量的元素、哈希表的键以及哈希表中的值进行枚举。枚举也用于将输入流指定到 SequenceInputStream 中。
注:此接口的功能与 Iterator 接口的功能是重复的。此外,Iterator接口添加了一个可选的移除操作,并使用较短的方法名。新的实现应该优先考虑使用 Iterator 接口而不是 Enumeration 接口。
有两个方法:
hasMoreElements() 测试此枚举是否包含更多的元素。
nextElement() 如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统