fix comment

This commit is contained in:
Looly 2020-09-06 02:30:36 +08:00
parent 784ad3e8f9
commit 24c9d354e9

View File

@ -312,7 +312,12 @@ public class TypeUtil {
}
/**
* 获取泛型变量和泛型实际类型的对应关系Map
* 获取泛型变量和泛型实际类型的对应关系Map例如
*
* <pre>
* T cn.hutool.test.User
* E java.lang.Integer
* </pre>
*
* @param clazz 被解析的包含泛型参数的类
* @return 泛型对应关系Map
@ -324,12 +329,12 @@ public class TypeUtil {
/**
* 获得泛型字段对应的泛型实际类型如果此变量没有对应的实际类型返回null
*
* @param type 实际类型明确的类
* @param type 实际类型明确的类
* @param field 字段
* @return 实际类型可能为Class等
*/
public static Type getActualType(Type type, Field field) {
if(null == field){
if (null == field) {
return null;
}
return getActualType(ObjectUtil.defaultIfNull(type, field.getDeclaringClass()), field.getGenericType());
@ -337,15 +342,20 @@ public class TypeUtil {
/**
* 获得泛型变量对应的泛型实际类型如果此变量没有对应的实际类型返回null
* 此方法可以处理
* 此方法可以处理
*
* @param type
* <pre>
* 1. 泛型化对象类似于Map&lt;User, Key&lt;Long&gt;&gt;
* 2. 泛型变量类似于T
* </pre>
*
* @param type
* @param typeVariable 泛型变量例如T等
* @return 实际类型可能为Class等
*/
public static Type getActualType(Type type, Type typeVariable) {
if (typeVariable instanceof ParameterizedType) {
return getActualType(type, (ParameterizedType)typeVariable);
return getActualType(type, (ParameterizedType) typeVariable);
}
if (typeVariable instanceof TypeVariable) {
@ -358,9 +368,9 @@ public class TypeUtil {
/**
* 获得泛型变量对应的泛型实际类型如果此变量没有对应的实际类型返回null
* 此方法可以处理
* 此方法可以处理复杂的泛型化对象类似于Map&lt;User, Key&lt;Long&gt;&gt;
*
* @param type
* @param type
* @param parameterizedType 泛型变量例如List&lt;T&gt;
* @return 实际类型可能为Class等
*/
@ -370,7 +380,7 @@ public class TypeUtil {
// 泛型对象中含有未被转换的泛型变量
if (TypeUtil.hasTypeVeriable(actualTypeArguments)) {
actualTypeArguments = getActualTypes(type , parameterizedType.getActualTypeArguments());
actualTypeArguments = getActualTypes(type, parameterizedType.getActualTypeArguments());
if (ArrayUtil.isNotEmpty(actualTypeArguments)) {
// 替换泛型变量为实际类型例如List<T>变为List<String>
parameterizedType = new ParameterizedTypeImpl(actualTypeArguments, parameterizedType.getOwnerType(), parameterizedType.getRawType());
@ -383,7 +393,7 @@ public class TypeUtil {
/**
* 获得泛型变量对应的泛型实际类型如果此变量没有对应的实际类型返回null
*
* @param type
* @param type
* @param typeVariables 泛型变量数组例如T等
* @return 实际类型数组可能为Class等
*/