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
()
| 291 | */ |
| 292 | |
| 293 | @Nullable final TypeToken<? super T> getGenericSuperclass() { |
| 294 | if (runtimeType instanceof TypeVariable) { |
| 295 | // First bound is always the super class, if one exists. |
| 296 | return boundAsSuperclass(((TypeVariable<?>) runtimeType).getBounds() [0]); |
| 297 | } |
| 298 | if (runtimeType instanceof WildcardType) { |
| 299 | // wildcard has one and only one upper bound. |
| 300 | return boundAsSuperclass(((WildcardType) runtimeType).getUpperBounds() [0]); |
| 301 | } |
| 302 | Type superclass = getRawType().getGenericSuperclass(); |
| 303 | if (superclass == null) { |
| 304 | return null; |
| 305 | } |
| 306 | @SuppressWarnings("unchecked") // super class of T |
| 307 | TypeToken<? super T> superToken = (TypeToken<? super T>) resolveSupertype(superclass); |
| 308 | return superToken; |
| 309 | } |
| 310 | |
| 311 | @Nullable |
| 312 | private TypeToken<? super T> boundAsSuperclass(Type bound) { |
no test coverage detected