[Feat] cn.hutool.core.util.StrUtil增加新方法 toStringOrEmptyStr, 调用对象的toString方法, null会返回空字符串 ""

This commit is contained in:
xujunwei 2024-04-02 16:41:12 +08:00
parent c694628154
commit 6996723c58

View File

@ -287,6 +287,18 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
return null == obj ? null : obj.toString();
}
/**
* 调用对象的toString方法null会返回空字符串 ""
*
* @param obj 对象
* @return {@link String }
* @author ahwei163@qq.com
*/
public static String toStringOrEmptyStr(Object obj) {
// obj为空时, 返回 null "null" 都不适用部分场景, 此处返回 "" 空字符串
return null == obj ? "" : obj.toString();
}
/**
* 创建StringBuilder对象
*