简体   繁体   中英

Java CommonsLang StringUtils.isBlank on instant

I know it's a silly question but here's my issue.

I'm working on an object and needed to check all the member variables for nullity, empty chars etc... but in my object I don't only have strings, I also have Instant and Booleans.

I've tried with some other methods from StringUtils and read the documentation but didn't find out any way to do so.

Any tip ? I know i can make the check without stringUtils but I can't believe they didn't figured a way out.

Thank you for your help!

You can use Objects class from java.util package to perform null checks in different type of objects, eg:

Date d = null;
Character c = new Character('c');
System.out.println(Objects.isNull(d));
System.out.println(Objects.isNull(c));

You can also use methods like requireNonNull to validate the values before sending to a method or a service.

Here 's javadoc for Objects class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM