Returns subtype of this with subclass as the raw class. For example, if this is Iterable and subclass is List, List is returned.
(Class<?> subclass)
| 410 | |
| 411 | |
| 412 | public final TypeToken<? extends T> getSubtype(Class<?> subclass) { |
| 413 | checkArgument( |
| 414 | !(runtimeType instanceof TypeVariable), |
| 415 | "Cannot get subtype of type variable <%s>", |
| 416 | this); |
| 417 | if (runtimeType instanceof WildcardType) { |
| 418 | return getSubtypeFromLowerBounds(subclass, ((WildcardType) runtimeType).getLowerBounds()); |
| 419 | } |
| 420 | // unwrap array type if necessary |
| 421 | if (isArray()) { |
| 422 | return getArraySubtype(subclass); |
| 423 | } |
| 424 | // At this point, it's either a raw class or parameterized type. |
| 425 | checkArgument(getRawType().isAssignableFrom(subclass), "%s isn't a subclass of %s", subclass, this); |
| 426 | Type resolvedTypeArgs = resolveTypeArgsForSubclass(subclass); |
| 427 | @SuppressWarnings("unchecked") // guarded by the isAssignableFrom() statement above |
| 428 | TypeToken<? extends T> subtype = (TypeToken<? extends T>) of(resolvedTypeArgs); |
| 429 | return subtype; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Returns true if this type is a supertype of the given {@code type}. "Supertype" is defined |
no test coverage detected