diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java index 97401035f719452c0d768cc2112d3bb7184726e7..82358d84bb7dd1e4491a4adb3de0ac268c7d854d 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java @@ -113,6 +113,21 @@ public final class ObjectUtils { return object; } + /** + * 获取非空或默认对象 + * + * @param object 对象 + * @param defaultObject 默认值 + * @param 范型 + * @return 非空或默认对象 + */ + public static T getOrDefault(T object, T defaultObject) { + if (object == null) { + return defaultObject; + } + return object; + } + /** * 获取对象哈希值 *