Convenient forType methods for ParameterizedTypeReference
Issue: SPR-16054
This commit is contained in:
@@ -53,6 +53,10 @@ public abstract class ParameterizedTypeReference<T> {
|
||||
this.type = parameterizedType.getActualTypeArguments()[0];
|
||||
}
|
||||
|
||||
private ParameterizedTypeReference(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
@@ -75,6 +79,19 @@ public abstract class ParameterizedTypeReference<T> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a {@code ParameterizedTypeReference} wrapping the given type.
|
||||
* @param type a generic type (possibly obtained via reflection,
|
||||
* e.g. from {@link java.lang.reflect.Method#getGenericReturnType()})
|
||||
* @return a corresponding reference which may be passed into
|
||||
* {@code ParameterizedTypeReference}-accepting methods
|
||||
* @since 4.3.12
|
||||
*/
|
||||
public static <T> ParameterizedTypeReference<T> forType(Type type) {
|
||||
return new ParameterizedTypeReference<T>(type) {
|
||||
};
|
||||
}
|
||||
|
||||
private static Class<?> findParameterizedTypeReferenceSubclass(Class<?> child) {
|
||||
Class<?> parent = child.getSuperclass();
|
||||
if (Object.class == parent) {
|
||||
|
||||
@@ -1340,6 +1340,19 @@ public class ResolvableType implements Serializable {
|
||||
return forType(type, variableResolver);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified {@link ParameterizedTypeReference}.
|
||||
* Note: The resulting {@link ResolvableType} may not be {@link Serializable}.
|
||||
* @param typeReference the reference to obtain the source type from
|
||||
* @return a {@link ResolvableType} for the specified {@link ParameterizedTypeReference}
|
||||
* @since 4.3.12
|
||||
* @see #forType(Type)
|
||||
*/
|
||||
public static ResolvableType forType(ParameterizedTypeReference<?> typeReference) {
|
||||
return forType(typeReference.getType(), null ,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified {@link Type} backed by a given
|
||||
* {@link VariableResolver}.
|
||||
|
||||
Reference in New Issue
Block a user