Home > Java > javaTutorial > body text

Detailed introduction to the use of spring assertions

零下一度
Release: 2017-06-28 09:23:18
Original
2078 people have browsed it

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     }
  }
Copy after login

##Assert.notNull source code:

1     public static void notNull(Object object, String message) {        
if (object == null) {3             throw new IllegalArgumentException(message);4         }5     }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!