I have a confusion on Gson TypeToken.getParameterized method.
When I pass a Primitive type on typeArguments, Gson will throw an IllegalArgumentException. Then I use TypeToken anonymous inner class instead and there is no exception will be thrown.
Checking the Gson source code and find that ParameterizedTypeImpl
will check typeArguments is Primitive:
static void checkNotPrimitive(Type type) {
checkArgument(!(type instanceof Class<?>) || !((Class<?>) type).isPrimitive());
}
public ParameterizedTypeImpl(..., Type... typeArguments) {
...
checkNotPrimitive(this.typeArguments[t]);
...
}
So why Gson TypeToken designed as it? Thank you.