@Test public void boundedWildcardTypeWithExtend_actualTypeParameterIsCastedToUpperBound() { TypeToken<List<? extends Number>> typeToken = TypeToken.of(new Safe<List<? extends Number>>() {}); assertThat(typeToken).isInstanceOf(TypeToken.ClassToken.class); TypeToken.ClassToken<List<? extends Number>> typeClassToken = (TypeToken.ClassToken<List<? extends Number>>) typeToken; TypeToken<Number> componentType = typeClassToken.getTypeArguments().at(0); assertThat(componentType).isInstanceOf(TypeToken.ClassToken.class); TypeToken.ClassToken<Number> componentClassType = (TypeToken.ClassToken<Number>) componentType; assertThat(componentClassType.getRawType()).isEqualTo(Number.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();  }