@Test public void testField_GenericField() throws Exception { Class<?> clazz = SubCalculator.class; Class<?> declaredClass = Calculator.class; Field field = declaredClass.getDeclaredField("fld"); Type result = TypeParameterResolver.resolveFieldType(field, clazz); assertEquals(String.class, result); }
public static Type resolveFieldType(Field field, Type srcType) { Type fieldType = field.getGenericType(); Class<?> declaringClass = field.getDeclaringClass(); return resolveType(fieldType, srcType, declaringClass); }
TypeParameterResolver { public static Type resolveFieldType(Field field, Type srcType) { Type fieldType = field.getGenericType(); Class<?> declaringClass = field.getDeclaringClass(); return resolveType(fieldType, srcType, declaringClass); } }
TypeParameterResolver { public static Type resolveFieldType(Field field, Type srcType) { Type fieldType = field.getGenericType(); Class<?> declaringClass = field.getDeclaringClass(); return resolveType(fieldType, srcType, declaringClass); } private  TypeParameterResolver(); }
TypeParameterResolver { public static Type resolveFieldType(Field field, Type srcType) { Type fieldType = field.getGenericType(); Class<?> declaringClass = field.getDeclaringClass(); return resolveType(fieldType, srcType, declaringClass); } private  TypeParameterResolver(); static Type resolveFieldType(Field field, Type srcType); static Type resolveReturnType(Method method, Type srcType); static Type[] resolveParamTypes(Method method, Type srcType); }
TypeParameterResolver { public static Type resolveFieldType(Field field, Type srcType) { Type fieldType = field.getGenericType(); Class<?> declaringClass = field.getDeclaringClass(); return resolveType(fieldType, srcType, declaringClass); } private  TypeParameterResolver(); static Type resolveFieldType(Field field, Type srcType); static Type resolveReturnType(Method method, Type srcType); static Type[] resolveParamTypes(Method method, Type srcType);  }