mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 22:27:59 +08:00
!1198 [Feat] cn.hutool.core.util.StrUtil增加新方法 toStringOrEmptyStr, 调用对象的toString方法, null会返回空字符串 ""
Merge pull request !1198 from ahwei/v5-dev
This commit is contained in:
commit
562d41386f
@ -287,6 +287,18 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
|||||||
return null == obj ? null : obj.toString();
|
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对象
|
* 创建StringBuilder对象
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user