关于ObjectUtils.isEmpty() 和 null 的区别
作者:编程牧马人 时间:2022-05-07 17:10:56
ObjectUtils.isEmpty()和null区别
分配内存和赋值的区别
isEmpty()
:判断值是否为空,即使已经分配内存,但没有赋值,依然是空null
:判断值是否为空,没有分配内存, 可能出现空指针异常
public class IsEmptyTest {
public static void main(String[] args) {
String s1 = new String();
String s2 = "abc";
String s3 = "";
System.out.println(s1 == null);
System.out.println(ObjectUtils.isEmpty(s1));
System.out.println("---------------");
System.out.println(s2 == null);
System.out.println(ObjectUtils.isEmpty(s2));
System.out.println("---------------");
System.out.println(s3 == null);
System.out.println(ObjectUtils.isEmpty(s3));
}
false
true
---------------
false
false
---------------
false
true
Spring5.3之后StringUtils.isEmpty被弃用
今天在尝试自己做一个转换器时,被系统提示isEmpty被启用,但是学习视频中没有:
但是页面可以显示处自己转换器要实现的结果:
根据提示改为hasLength和hasText后,页面均没有实现想要的结果,显示为null
解决办法
就用isEmpyt,或者改为他描述的另一种方法:ObjectUtils.isEmpty
来源:https://blog.csdn.net/m_shang/article/details/122192212
标签:ObjectUtils,isEmpty,null
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决使用ProcessBuilder踩到的坑及注意事项
2023-11-24 01:37:55
![](https://img.aspxhome.com/file/2023/0/59500_0s.png)
Spring boot + mybatis + Vue.js + ElementUI 实现数据的增删改查实例代码(一)
2021-12-29 08:15:07
![](https://img.aspxhome.com/file/2023/5/65725_0s.jpg)
必须要学会的JMM与volatile
2021-07-30 14:07:53
![](https://img.aspxhome.com/file/2023/2/61932_0s.png)
Java String对象使用方法详解
2023-12-14 14:43:52
Spring Boot+Shiro实现一个Http请求的Basic认证
2022-06-01 22:22:31
![](https://img.aspxhome.com/file/2023/5/61065_0s.png)
Java详细分析String类与StringBuffer和StringBuilder的使用方法
2022-04-23 15:23:30
![](https://img.aspxhome.com/file/2023/6/64946_0s.png)
一文搞懂c# await,async执行流
2023-07-14 01:22:35
![](https://img.aspxhome.com/file/2023/5/67055_0s.png)
java基础的详细了解第六天
2021-11-05 16:18:49
![](https://img.aspxhome.com/file/2023/8/65348_0s.png)
C# 一个WCF简单实例
2023-07-12 20:53:43
![](https://img.aspxhome.com/file/2023/5/66125_0s.jpg)
Spring Cloud Ribbon配置详解
2023-11-25 01:32:50
java利用多线程和Socket实现猜拳游戏
2022-10-03 08:03:30
![](https://img.aspxhome.com/file/2023/9/64549_0s.jpg)
java实现快速排序图文详解
2022-10-11 16:35:18
![](https://img.aspxhome.com/file/2023/3/65363_0s.jpg)
OpenCV实现直线拟合
2023-06-22 15:22:37
![](https://img.aspxhome.com/file/2023/4/92494_0s.jpg)
Java虚拟机内存结构及编码实战分享
2023-11-29 13:47:47
![](https://img.aspxhome.com/file/2023/8/59518_0s.png)
Java使用ExecutorService来停止线程服务
2023-01-25 12:10:56
Java仿12306图片验证码
2022-09-29 05:36:08
![](https://img.aspxhome.com/file/2023/1/60991_0s.jpg)
Spring的@Autowired加到接口上但获取的是实现类的问题
2023-08-23 21:32:21
自己写的java日志类和方法代码分享
2021-08-18 19:34:13
java设计模式--三种工厂模式详解
2023-11-29 09:54:06
![](https://img.aspxhome.com/file/2023/7/60337_0s.png)
Java 栈与队列超详细分析讲解
2023-08-15 01:09:07
![](https://img.aspxhome.com/file/2023/1/58051_0s.png)