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必須不能為空。如果為空就拋出異常。
轉自:http://jack-chen10.blog.163.com/blog/static/6775128201348545984/