@Test void testGetMemberValueTypeFromField() throws NoSuchFieldException { Class<?> fieldType = getMemberValueType(SomeType.class.getDeclaredField("field1")); assertEquals(String.class, fieldType); }
public static Class<?> getMemberValueType(Member member) { if (member instanceof Method) { final Method method = (Method) member; return method.getReturnType(); } else if (member instanceof Field) { final Field field = (Field) member; return field.getType(); } throw new IllegalStateException( String.format(UNSUPPORTED_MEMBER_TYPE_EXCEPTION_MESSAGE, member.getClass().getName()) ); }
ReflectionUtils { public static Class<?> getMemberValueType(Member member) { if (member instanceof Method) { final Method method = (Method) member; return method.getReturnType(); } else if (member instanceof Field) { final Field field = (Field) member; return field.getType(); } throw new IllegalStateException( String.format(UNSUPPORTED_MEMBER_TYPE_EXCEPTION_MESSAGE, member.getClass().getName()) ); } }
ReflectionUtils { public static Class<?> getMemberValueType(Member member) { if (member instanceof Method) { final Method method = (Method) member; return method.getReturnType(); } else if (member instanceof Field) { final Field field = (Field) member; return field.getType(); } throw new IllegalStateException( String.format(UNSUPPORTED_MEMBER_TYPE_EXCEPTION_MESSAGE, member.getClass().getName()) ); } private  ReflectionUtils(); }
ReflectionUtils { public static Class<?> getMemberValueType(Member member) { if (member instanceof Method) { final Method method = (Method) member; return method.getReturnType(); } else if (member instanceof Field) { final Field field = (Field) member; return field.getType(); } throw new IllegalStateException( String.format(UNSUPPORTED_MEMBER_TYPE_EXCEPTION_MESSAGE, member.getClass().getName()) ); } private  ReflectionUtils(); @SuppressWarnings("unchecked") static R getFieldValue(Field field, Object object); static void setFieldValue(Field field, Object object, T value); static Class<?> declaringClass(Class<?> instanceClass, String methodName, Class<?>... parameterTypes); static boolean hasEqualsMethod(Class<?> type); @SuppressWarnings("unchecked") static boolean explicitlyUnequal(Object value, Object otherValue); static T ensureAccessible(T member); static boolean isAccessible(AccessibleObject member); static boolean isNonFinalPublicMember(Member member); static Iterable<Field> fieldsOf(Class<?> clazz); static Method methodOf(Class<?> clazz, String methodName, Class<?>... parameterTypes); static Iterable<Method> methodsOf(Class<?> clazz); static Class<?> resolvePrimitiveWrapperType(Class<?> primitiveType); static Type resolvePrimitiveWrapperTypeIfPrimitive(Type type); static Type unwrapIfType(Type type, Class<?>... wrapperTypes); static boolean isTransient(Field field); static Optional<Class<?>> resolveGenericType(Field field, int genericTypeIndex); static Optional<Class<?>> resolveMemberGenericType(Member member, int genericTypeIndex); @SuppressWarnings("unchecked") static R invokeAndGetMethodValue(Method method, Object object); @SuppressWarnings("unchecked") static R getMemberValue(Member member, Object target); static Class<?> getMemberValueType(Member member); static Type getMemberGenericType(Member member); static String getMemberGenericString(Member member); }
ReflectionUtils { public static Class<?> getMemberValueType(Member member) { if (member instanceof Method) { final Method method = (Method) member; return method.getReturnType(); } else if (member instanceof Field) { final Field field = (Field) member; return field.getType(); } throw new IllegalStateException( String.format(UNSUPPORTED_MEMBER_TYPE_EXCEPTION_MESSAGE, member.getClass().getName()) ); } private  ReflectionUtils(); @SuppressWarnings("unchecked") static R getFieldValue(Field field, Object object); static void setFieldValue(Field field, Object object, T value); static Class<?> declaringClass(Class<?> instanceClass, String methodName, Class<?>... parameterTypes); static boolean hasEqualsMethod(Class<?> type); @SuppressWarnings("unchecked") static boolean explicitlyUnequal(Object value, Object otherValue); static T ensureAccessible(T member); static boolean isAccessible(AccessibleObject member); static boolean isNonFinalPublicMember(Member member); static Iterable<Field> fieldsOf(Class<?> clazz); static Method methodOf(Class<?> clazz, String methodName, Class<?>... parameterTypes); static Iterable<Method> methodsOf(Class<?> clazz); static Class<?> resolvePrimitiveWrapperType(Class<?> primitiveType); static Type resolvePrimitiveWrapperTypeIfPrimitive(Type type); static Type unwrapIfType(Type type, Class<?>... wrapperTypes); static boolean isTransient(Field field); static Optional<Class<?>> resolveGenericType(Field field, int genericTypeIndex); static Optional<Class<?>> resolveMemberGenericType(Member member, int genericTypeIndex); @SuppressWarnings("unchecked") static R invokeAndGetMethodValue(Method method, Object object); @SuppressWarnings("unchecked") static R getMemberValue(Member member, Object target); static Class<?> getMemberValueType(Member member); static Type getMemberGenericType(Member member); static String getMemberGenericString(Member member);  }