refactor(devkit-utils): Changed the location of some codes.

This commit is contained in:
Zihlu Wang
2023-09-19 08:51:42 +08:00
parent f80c47e8ad
commit aa3213cbbe
@@ -178,6 +178,22 @@ public final class MapUtil {
method.invoke(obj, fieldValue); method.invoke(obj, fieldValue);
} }
/**
* Casts the specified value to the required type.
*
* @param value the value to be cast
* @param requiredType the type to which the value should be cast
* @param <T> the type to which the value should be cast
* @return the cast value, or null if the value cannot be cast to the
* required type
*/
public static <T> T cast(Object value, Class<T> requiredType) {
if (requiredType.isInstance(value)) {
return requiredType.cast(value);
}
return null;
}
/** /**
* Constructs a method name based on the given prefix and field name. * Constructs a method name based on the given prefix and field name.
* *
@@ -203,20 +219,4 @@ public final class MapUtil {
return String.valueOf(obj); return String.valueOf(obj);
} }
} }
/**
* Casts the specified value to the required type.
*
* @param value the value to be cast
* @param requiredType the type to which the value should be cast
* @param <T> the type to which the value should be cast
* @return the cast value, or null if the value cannot be cast to the
* required type
*/
public static <T> T cast(Object value, Class<T> requiredType) {
if (requiredType.isInstance(value)) {
return requiredType.cast(value);
}
return null;
}
} }