guava/src/com/google/common/reflect/TypeToken.java
private boolean is(Type formalType, TypeVariable<?> declaration) {
    if (runtimeType.equals(formalType)) {
      return true;
    }
    if (formalType instanceof WildcardType) {
      WildcardType your = canonicalizeWildcardType(declaration, (WildcardType) formalType);
      // if "formalType" is <? extends Foo>, "this" can be:
      // Foo, SubFoo, <? extends Foo>, <? extends SubFoo>, <T extends Foo> or
      // <T extends SubFoo>.
      // if "formalType" is <? super Foo>, "this" can be:
      // Foo, SuperFoo, <? super Foo> or <? super SuperFoo>.
      return every(your.getUpperBounds()).isSupertypeOf(runtimeType)
          && every(your.getLowerBounds()).isSubtypeOf(runtimeType);
    }
    return canonicalizeWildcardsInType(runtimeType).equals(canonicalizeWildcardsInType(formalType));
  }
private boolean is(Type formalType, TypeVariable<?> declaration) {
    if (runtimeType.equals(formalType)) {
      return true;
    }
    if (formalType instanceof WildcardType) {
      WildcardType your = canonicalizeWildcardType(declaration, (WildcardType) formalType);
      // if "formalType" is <? extends Foo>, "this" can be:
      // Foo, SubFoo, <? extends Foo>, <? extends SubFoo>, <T extends Foo> or
      // <T extends SubFoo>.
      // if "formalType" is <? super Foo>, "this" can be:
      // Foo, SuperFoo, <? super Foo> or <? super SuperFoo>.
      return every(your.getUpperBounds()).isSupertypeOf(runtimeType)
          && every(your.getLowerBounds()).isSubtypeOf(runtimeType);
    }
    return canonicalizeWildcardsInType(runtimeType).equals(canonicalizeWildcardsInType(formalType));
  }
{@code A.is(B)} is defined as {@code Foo<A>.isSubtypeOf(Foo<B>)}.

<p>Specifically, returns true if any of the following conditions is met:

<ol>
<li>'this' and {@code formalType} are equal.
<li>'this' and {@code formalType} have equal canonical form.
<li>{@code formalType} is {@code <? extends Foo>} and 'this' is a subtype of {@code Foo}.
<li>{@code formalType} is {@code <? super Foo>} and 'this' is a supertype of {@code Foo}.
</ol>

Note that condition 2 isn't technically accurate under the context of a recursively bounded
type variables. For example, {@code Enum<? extends Enum<E>>} canonicalizes to {@code Enum<?>}
where {@code E} is the type variable declared on the {@code Enum} class declaration. It's
technically <em>not</em> true that {@code Foo<Enum<? extends Enum<E>>>} is a subtype of {@code
Foo<Enum<?>>} according to JLS. See testRecursiveWildcardSubtypeBug() for a real example.

<p>It appears that properly handling recursive type bounds in the presence of implicit type
bounds is not easy. For now we punt, hoping that this defect should rarely cause issues in real
code.

@param formalType is {@code Foo<formalType>} a supertype of {@code Foo<T>}?
@param declaration The type variable in the context of a parameterized type. Used to infer type
bound when {@code formalType} is a wildcard with implicit upper bound.