@Test public void genericArrayType_rawTypeIsCorrectlyCaptured() { TypeToken<List<String>[]> typeToken = TypeToken.of(new Safe<List<String>[]>() {}); assertThat(typeToken).isInstanceOf(TypeToken.ArrayToken.class); TypeToken.ArrayToken<List<String>[]> arrayToken = (TypeToken.ArrayToken<List<String>[]>) typeToken; TypeToken<List<String>> componentType = (TypeToken<List<String>>) arrayToken.getComponentType(); assertThat(componentType).isInstanceOf(TypeToken.ClassToken.class); TypeToken.ClassToken<List<String>> componentClassType = (TypeToken.ClassToken<List<String>>) componentType; assertThat(componentClassType.getRawType()).isEqualTo(List.class); TypeToken<String> argumentType = ((TypeToken.ClassToken<List<String>>) componentType).getTypeArguments().at(0); assertThat(argumentType).isInstanceOf(TypeToken.ClassToken.class); TypeToken.ClassToken<String> argumentClassType = (TypeToken.ClassToken<String>) argumentType; assertThat(argumentClassType.getRawType()).isEqualTo(String.class); }
@NonNull public static <T> TypeToken<T> of(@NonNull Safe<T> token) { Type superclass = token.getClass().getGenericSuperclass(); if (superclass instanceof Class) { throw new IllegalArgumentException("Missing type parameters"); } @SuppressWarnings("ConstantConditions") Type type = ((ParameterizedType) superclass).getActualTypeArguments()[0]; return of(type); }
TypeToken { @NonNull public static <T> TypeToken<T> of(@NonNull Safe<T> token) { Type superclass = token.getClass().getGenericSuperclass(); if (superclass instanceof Class) { throw new IllegalArgumentException("Missing type parameters"); } @SuppressWarnings("ConstantConditions") Type type = ((ParameterizedType) superclass).getActualTypeArguments()[0]; return of(type); } }
TypeToken { @NonNull public static <T> TypeToken<T> of(@NonNull Safe<T> token) { Type superclass = token.getClass().getGenericSuperclass(); if (superclass instanceof Class) { throw new IllegalArgumentException("Missing type parameters"); } @SuppressWarnings("ConstantConditions") Type type = ((ParameterizedType) superclass).getActualTypeArguments()[0]; return of(type); } private  TypeToken(); }
TypeToken { @NonNull public static <T> TypeToken<T> of(@NonNull Safe<T> token) { Type superclass = token.getClass().getGenericSuperclass(); if (superclass instanceof Class) { throw new IllegalArgumentException("Missing type parameters"); } @SuppressWarnings("ConstantConditions") Type type = ((ParameterizedType) superclass).getActualTypeArguments()[0]; return of(type); } private  TypeToken(); @NonNull static TypeToken<T> of(@NonNull Safe<T> token); @NonNull static TypeToken<T> of(@NonNull Class<T> typeToken); @NonNull @Override String toString(); }
TypeToken { @NonNull public static <T> TypeToken<T> of(@NonNull Safe<T> token) { Type superclass = token.getClass().getGenericSuperclass(); if (superclass instanceof Class) { throw new IllegalArgumentException("Missing type parameters"); } @SuppressWarnings("ConstantConditions") Type type = ((ParameterizedType) superclass).getActualTypeArguments()[0]; return of(type); } private  TypeToken(); @NonNull static TypeToken<T> of(@NonNull Safe<T> token); @NonNull static TypeToken<T> of(@NonNull Class<T> typeToken); @NonNull @Override String toString();  }