Skip to content

Commit eacba7a

Browse files
committed
see 02/08 log
1 parent e0948ff commit eacba7a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

utilcode/src/main/java/com/blankj/utilcode/util/ObjectUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ public static <T> T requireNonNull(T object, String message) {
113113
return object;
114114
}
115115

116+
/**
117+
* 获取非空或默认对象
118+
*
119+
* @param object 对象
120+
* @param defaultObject 默认值
121+
* @param <T> 范型
122+
* @return 非空或默认对象
123+
*/
124+
public static <T> T getOrDefault(T object, T defaultObject) {
125+
if (object == null) {
126+
return defaultObject;
127+
}
128+
return object;
129+
}
130+
116131
/**
117132
* 获取对象哈希值
118133
*

0 commit comments

Comments
 (0)