TypeUtil { public static Class<?> getFirstTypeArgument(Type type) { if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; return getRawClass(p.getActualTypeArguments()[0]); } else { return null; } } private  TypeUtil(); static Class<?> getRawClass(Type type); static Class<?> getFirstTypeArgument(Type type);  }
@Test public void getFirstTypeArgument() throws Exception { assertThat(TypeUtil.getFirstTypeArgument(getClass().getField("boolField").getGenericType())).isNull(); assertThat(TypeUtil.getFirstTypeArgument(getClass().getField("stringListField").getGenericType())).isEqualTo(String.class); assertThat(TypeUtil.getFirstTypeArgument(getClass().getField("stringListListField").getGenericType())).isEqualTo(List.class); }