File tree 1 file changed +8
-5
lines changed
gson/src/main/java/com/google/gson/internal
1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -145,11 +145,14 @@ public static Class<?> getRawType(Type type) {
145
145
Type componentType = ((GenericArrayType ) type ).getGenericComponentType ();
146
146
return Array .newInstance (getRawType (componentType ), 0 ).getClass ();
147
147
148
- } else if (type instanceof TypeVariable ) {
149
- // we could use the variable's bounds, but that won't work if there are multiple.
150
- // having a raw type that's more general than necessary is okay
151
- return Object .class ;
152
-
148
+ } else if (type instanceof TypeVariable <?>) {
149
+ TypeVariable <?> typeVariable = (TypeVariable <?>) type ;
150
+ // approximate the raw type with the bound of type type variable, if there are
151
+ // multiple bounds, all we can do is picking the first one
152
+ Type [] bounds = typeVariable .getBounds ();
153
+ // Javadoc specifies some bound is always returned, Object if not specified
154
+ assert bounds .length > 0 ;
155
+ return getRawType (bounds [0 ]);
153
156
} else if (type instanceof WildcardType ) {
154
157
Type [] bounds = ((WildcardType ) type ).getUpperBounds ();
155
158
// Currently the JLS only permits one bound for wildcards so using first bound is safe
You can’t perform that action at this time.
0 commit comments