### Question:
Generics { public static Type getGenericInterfaceType(Object instance, Class<?> iface, int position) { Class<?> type = instance.getClass(); while (type != Object.class) { for (Type genericType : type.getGenericInterfaces()) { if (genericType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericType; if (parameterizedType.getRawType() == iface) { return parameterizedType.getActualTypeArguments()[position]; } } } type = type.getSuperclass(); } return null; } private  Generics(); static Type getGenericClassType(Object instance, Class<?> clazz, int position); static Type getGenericInterfaceType(Object instance, Class<?> iface, int position);  }### Answer:
@Test public void testGetInterfaceType() throws Exception { assertEquals(String.class, Generics.getGenericInterfaceType(new ConcreteInterface(), GenericInterface.class, 0)); assertEquals(SomeClass.class, Generics.getGenericInterfaceType(new ConcreteInterface(), GenericInterface.class, 1)); }