Returns the generic superclass of this type or null if the type represents Object or an interface. This method is similar but different from Class#getGenericSuperclass. For example, new TypeToken () {.getGenericSuperclass()} will return {@code new Type
()
| 292 | */ |
| 293 | |
| 294 | @Nullable final TypeToken<? super T> getGenericSuperclass() { |
| 295 | if (runtimeType instanceof TypeVariable) { |
| 296 | // First bound is always the super class, if one exists. |
| 297 | return boundAsSuperclass(((TypeVariable<?>) runtimeType).getBounds() [0]); |
| 298 | } |
| 299 | if (runtimeType instanceof WildcardType) { |
| 300 | // wildcard has one and only one upper bound. |
| 301 | return boundAsSuperclass(((WildcardType) runtimeType).getUpperBounds() [0]); |
| 302 | } |
| 303 | Type superclass = getRawType().getGenericSuperclass(); |
| 304 | if (superclass == null) { |
| 305 | return null; |
| 306 | } |
| 307 | @SuppressWarnings("unchecked") // super class of T |
| 308 | TypeToken<? super T> superToken = (TypeToken<? super T>) resolveSupertype(superclass); |
| 309 | return superToken; |
| 310 | } |
| 311 | |
| 312 | @Nullable |
| 313 | private TypeToken<? super T> boundAsSuperclass(Type bound) { |
no test coverage detected