springframework中Assert的用法

使用assert的好处就是比较简洁,不用加try catch就可以附加一些预期的提示信息,方便定位问题

1 import org.springframework.util.Assert;
2 
3 public class Demo {
4     public static void main(String[] args) {
5         String location = null;
6         Assert.notNull(location, "Location must not be null");
7         System.out.println("location = [" + location + "]");
8     }
9 }
Demo

 

Output:

 

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

 

转载于:https://www.cnblogs.com/TomJay/p/9670670.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值