TypeToken { public final Type getJavaType() { return javaType; } protected  TypeToken(); private  TypeToken(Type javaType); final Type getJavaType(); static TypeToken<T> of(Class<T> clazz); static TypeToken<?> of(Type type);  }
@Test public void test() { TypeToken<?> typeToken = new TypeToken<Collection<String>>() { }; Assert.assertTrue(typeToken.getJavaType() instanceof ParameterizedType); Assert.assertEquals(((ParameterizedType) typeToken.getJavaType()).getRawType(), Collection.class); Assert.assertEquals(((ParameterizedType) typeToken.getJavaType()).getActualTypeArguments().length, 1); Assert.assertEquals(((ParameterizedType) typeToken.getJavaType()).getActualTypeArguments()[0], String.class); }
@Test public <D> void typeVariableTest() { TypeToken<?> typeToken = new TypeToken<D>() { }; Assert.assertTrue(typeToken.getJavaType() instanceof TypeVariable); Assert.assertEquals(((TypeVariable) typeToken.getJavaType()).getName(), "D"); }