Types { public static TypeToken<?> getArrayItemType(TypeToken<?> type) { if (type.isSubtypeOf(Collection.class)) { return type.resolveType(Collection.class.getTypeParameters()[0]); } else if (type.isArray()) { return type.getComponentType(); } return null; }  static boolean isArrayType(TypeToken<?> type); static boolean isEnumType(TypeToken<?> type); static boolean isMapType(TypeToken<?> type); static boolean isConcreteType(Type type); static boolean isJavaClientEntity(TypeToken<?> type); static boolean isTypeVariable(TypeToken<?> type); static boolean isCollectionResponseType(TypeToken<?> type); static boolean isWildcardType(TypeToken<?> type); static boolean isObject(TypeToken<?> type); static String getSimpleName(TypeToken<?> type, ApiSerializationConfig config); static TypeToken<?> getArrayItemType(TypeToken<?> type); static TypeToken<?> getTypeParameter(TypeToken<?> type, int index);  }
@Test public void getArrayItemType_basic() { assertThat(Types.getArrayItemType(TypeToken.of(String[].class))).isEqualTo(STRING); assertThat(Types.getArrayItemType(TypeToken.of(int[].class))).isEqualTo(INT); }
@Test public void getArrayItemType_genericArray() { class Foo extends Base<String[]> {} ParameterizedType type = (ParameterizedType) Foo.class.getGenericSuperclass(); assertThat(Types.getArrayItemType(TypeToken.of(type.getActualTypeArguments()[0]))) .isEqualTo(STRING); }
@Test public void getArrayItemType_genericCollection() { class Foo extends Base<Collection<String>> {} ParameterizedType type = (ParameterizedType) Foo.class.getGenericSuperclass(); assertThat(Types.getArrayItemType(TypeToken.of(type.getActualTypeArguments()[0]))) .isEqualTo(STRING); }
@Test public void getArrayItemType_nonArray() { assertThat(Types.getArrayItemType(STRING)).isNull(); }