@Test public void plainClassTypeWithoutSafe_rawTypeIsCorrectlyCaptured() { TypeToken<Foo> typeToken = TypeToken.of(Foo.class); assertThat(typeToken).isInstanceOf(TypeToken.ClassToken.class); TypeToken.ClassToken<Foo> typeClassToken = (TypeToken.ClassToken<Foo>) typeToken; assertThat(typeClassToken.getRawType()).isEqualTo(Foo.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();  }