org.springframework.util.Assert


使用assert的好處就是比較簡介,不用加try catch就可以附加一些預期的提示信息,方便定位問題

import org.springframework.util.Assert;

public class Demo {
    public static void main(String[] args) {
        String location = null;
        Assert.notNull(location, "Location must not be null");
        System.out.println("location = [" + location + "]");
    }
}

Output:

Exception in thread "main" java.lang.IllegalArgumentException: Location must not be null
	at org.springframework.util.Assert.notNull(Assert.java:115)
	at Demo.main(Demo.java:9)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM