mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
将ObjUtil.defaultIfNull检验参数类型从Object改为泛型
This commit is contained in:
@@ -13,7 +13,11 @@ import cn.hutool.core.text.StrUtil;
|
|||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -305,8 +309,7 @@ public class ObjUtil {
|
|||||||
* @return 处理后的返回值
|
* @return 处理后的返回值
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public static <T, R> R defaultIfNull(
|
public static <T, R> R defaultIfNull(final T source, final Function<? super T, ? extends R> handler, final Supplier<? extends R> defaultSupplier) {
|
||||||
final T source, final Function<? super T, ? extends R> handler, final Supplier<? extends R> defaultSupplier) {
|
|
||||||
if (isNotNull(source)) {
|
if (isNotNull(source)) {
|
||||||
return handler.apply(source);
|
return handler.apply(source);
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,7 @@ public class ObjUtilTest {
|
|||||||
public Obj clone() {
|
public Obj clone() {
|
||||||
try {
|
try {
|
||||||
return (Obj) super.clone();
|
return (Obj) super.clone();
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (final CloneNotSupportedException e) {
|
||||||
throw new CloneRuntimeException(e);
|
throw new CloneRuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ public class ObjUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cloneIfPossibleTest() {
|
public void cloneIfPossibleTest() {
|
||||||
String a = "a";
|
final String a = "a";
|
||||||
final String a2 = ObjUtil.cloneIfPossible(a);
|
final String a2 = ObjUtil.cloneIfPossible(a);
|
||||||
Assert.assertNotSame(a, a2);
|
Assert.assertNotSame(a, a2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user