core/src/com/google/inject/internal/InjectorImpl.java
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
      Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
    Type typeLiteralType = key.getTypeLiteral().getType();
    if (!(typeLiteralType instanceof ParameterizedType)) {
      throw errors.cannotInjectRawTypeLiteral().toException();
    }

    ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
    Type innerType = parameterizedType.getActualTypeArguments()[0];

    // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If
    // this proves problematic, we can probably fix TypeLiteral to support type variables
    if (!(innerType instanceof Class)
        && !(innerType instanceof GenericArrayType)
        && !(innerType instanceof ParameterizedType)) {
      throw errors.cannotInjectTypeLiteralOf(innerType).toException();
    }

    @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
    TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
    InternalFactory<TypeLiteral<T>> factory =
        new ConstantFactory<TypeLiteral<T>>(Initializables.of(value));
    return new InstanceBindingImpl<TypeLiteral<T>>(
        this,
        key,
        SourceProvider.UNKNOWN_SOURCE,
        factory,
        ImmutableSet.<InjectionPoint>of(),
        value);
  }
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(
      Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException {
    Type typeLiteralType = key.getTypeLiteral().getType();
    if (!(typeLiteralType instanceof ParameterizedType)) {
      throw errors.cannotInjectRawTypeLiteral().toException();
    }

    ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType;
    Type innerType = parameterizedType.getActualTypeArguments()[0];

    // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If
    // this proves problematic, we can probably fix TypeLiteral to support type variables
    if (!(innerType instanceof Class)
        && !(innerType instanceof GenericArrayType)
        && !(innerType instanceof ParameterizedType)) {
      throw errors.cannotInjectTypeLiteralOf(innerType).toException();
    }

    @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe
    TypeLiteral<T> value = (TypeLiteral<T>) TypeLiteral.get(innerType);
    InternalFactory<TypeLiteral<T>> factory =
        new ConstantFactory<TypeLiteral<T>>(Initializables.of(value));
    return new InstanceBindingImpl<TypeLiteral<T>>(
        this,
        key,
        SourceProvider.UNKNOWN_SOURCE,
        factory,
        ImmutableSet.<InjectionPoint>of(),
        value);
  }
private < T > BindingImpl < TypeLiteral < T > > createTypeLiteralBinding ( Key < TypeLiteral < T > > key , Errors errors ) throws ErrorsException { Type typeLiteralType = key . getTypeLiteral ( ) . getType ( ) ; if ( ! ( typeLiteralType instanceof ParameterizedType ) ) { throw errors . cannotInjectRawTypeLiteral ( ) . toException ( ) ; } ParameterizedType parameterizedType = ( ParameterizedType ) typeLiteralType ; Type innerType = parameterizedType . getActualTypeArguments ( ) [ 0 ] ; // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If // this proves problematic, we can probably fix TypeLiteral to support type variables if ( ! ( innerType instanceof Class ) && ! ( innerType instanceof GenericArrayType ) && ! ( innerType instanceof ParameterizedType ) ) { throw errors . cannotInjectTypeLiteralOf ( innerType ) . toException ( ) ; } @ SuppressWarnings ( "unchecked" ) // by definition, innerType == T, so this is safe TypeLiteral < T > value = ( TypeLiteral < T > ) TypeLiteral . get ( innerType ) ; InternalFactory < TypeLiteral < T > > factory = new ConstantFactory < TypeLiteral < T > > ( Initializables . of ( value ) ) ; return new InstanceBindingImpl < TypeLiteral < T > > ( this , key , SourceProvider . UNKNOWN_SOURCE , factory , ImmutableSet . < InjectionPoint > of ( ) , value ) ; }
Converts a binding for a {@code Key<TypeLiteral<T>>} to the value {@code TypeLiteral<T>}. It's
a bit awkward because we have to pull out the inner type in the type literal.
Converts a binding for a {