Here you can find the source of getGenericType(@Nullable Type genericType)
Parameter | Description |
---|---|
genericType | the type to get the generic type from |
@Nullable public static Class<?> getGenericType(@Nullable Type genericType)
//package com.java2s; //License from project: Open Source License import javax.annotation.Nullable; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**//from w ww . j a v a 2 s . co m * Retrieves the generic subtype of the given type. * * @param genericType the type to get the generic type from * @return the generic type, or null if not applicable */ @Nullable public static Class<?> getGenericType(@Nullable Type genericType) { if (genericType != null && genericType instanceof ParameterizedType) { Type[] types = ((ParameterizedType) genericType).getActualTypeArguments(); if (types.length > 0 && types[0] instanceof Class<?>) { return (Class<?>) types[0]; } } return null; } }