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