Assertion is to determine that an actual value is what you expect, and if it is different, throw an exception.
Assert is often used for:
1. Determine whether the parameters of the method are normal values.
2. Used in juit.
1 import org.springframework.util.Assert; 2 3 /** 4 * Created by hunt on 2017/6/27. 5 */ 6 public class AssertTest { 7 public static void main(String[] args) { 8 String name = null; 9 Assert.notNull(name,"name不能为空");10 } }
1 public static void notNull(Object object, String message) { if (object == null) {3 throw new IllegalArgumentException(message);4 }5 }
The above is the detailed content of Detailed introduction to the use of spring assertions. For more information, please follow other related articles on the PHP Chinese website!