Home >Java >javaTutorial >Detailed introduction to the use of spring assertions

Detailed introduction to the use of spring assertions

零下一度
零下一度Original
2017-06-28 09:23:182100browse

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     }
  }

##Assert.notNull source code:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn