@Test public void test_getGenericInterfaceTypeParameter() { class MyListClass extends ArrayList<String> implements List<String> { } assertThat(getGenericInterfaceTypeParameters(MyListClass.class, List.class)[0]).isEqualTo(String.class); }
public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { Objects.requireNonNull(clazz, "Class parameter must be given."); Objects.requireNonNull(interfaceType, "Interface parameter must be given."); for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(parameterizedType.getRawType().equals(interfaceType)){ return parameterizedType.getActualTypeArguments(); } } } return EMPTY_TYPE_ARRAY; }
TypeLiteral implements Serializable { public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { Objects.requireNonNull(clazz, "Class parameter must be given."); Objects.requireNonNull(interfaceType, "Interface parameter must be given."); for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(parameterizedType.getRawType().equals(interfaceType)){ return parameterizedType.getActualTypeArguments(); } } } return EMPTY_TYPE_ARRAY; } }
TypeLiteral implements Serializable { public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { Objects.requireNonNull(clazz, "Class parameter must be given."); Objects.requireNonNull(interfaceType, "Interface parameter must be given."); for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(parameterizedType.getRawType().equals(interfaceType)){ return parameterizedType.getActualTypeArguments(); } } } return EMPTY_TYPE_ARRAY; } TypeLiteral(Type definedType);  TypeLiteral(); }
TypeLiteral implements Serializable { public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { Objects.requireNonNull(clazz, "Class parameter must be given."); Objects.requireNonNull(interfaceType, "Interface parameter must be given."); for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(parameterizedType.getRawType().equals(interfaceType)){ return parameterizedType.getActualTypeArguments(); } } } return EMPTY_TYPE_ARRAY; } TypeLiteral(Type definedType);  TypeLiteral(); static TypeLiteral<R> of(Type type); static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType); static Type[] getTypeParameters(Type type); final Type getType(); @SuppressWarnings("unchecked") final Class<T> getRawType(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
TypeLiteral implements Serializable { public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { Objects.requireNonNull(clazz, "Class parameter must be given."); Objects.requireNonNull(interfaceType, "Interface parameter must be given."); for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(parameterizedType.getRawType().equals(interfaceType)){ return parameterizedType.getActualTypeArguments(); } } } return EMPTY_TYPE_ARRAY; } TypeLiteral(Type definedType);  TypeLiteral(); static TypeLiteral<R> of(Type type); static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType); static Type[] getTypeParameters(Type type); final Type getType(); @SuppressWarnings("unchecked") final Class<T> getRawType(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }