Types { static Type arrayComponentType(Type type) { if (type instanceof GenericArrayType) { return ((GenericArrayType) type).getGenericComponentType(); } else if (type instanceof Class) { return ((Class<?>) type).getComponentType(); } else { return null; } } private  Types(); static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments); static GenericArrayType arrayOf(Type componentType); static WildcardType subtypeOf(Type bound); static WildcardType supertypeOf(Type bound); static Class<?> getRawType(Type type); static Type collectionElementType(Type context, Class<?> contextRawType);  }
@Test public void arrayComponentType() throws Exception { assertThat(Types.arrayComponentType(String[][].class)).isEqualTo(String[].class); assertThat(Types.arrayComponentType(String[].class)).isEqualTo(String.class); Type arrayOfMapOfStringIntegerType = TypesTest.class.getDeclaredField( "arrayOfMapOfStringInteger").getGenericType(); Type mapOfStringIntegerType = TypesTest.class.getDeclaredField( "mapOfStringInteger").getGenericType(); assertThat(Types.arrayComponentType(arrayOfMapOfStringIntegerType)) .isEqualTo(mapOfStringIntegerType); }