core/src/com/google/inject/internal/InjectorImpl.java
private <T> BindingImpl<T> createImplementedByBinding(
      Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors)
      throws ErrorsException {
    Class<?> rawType = key.getTypeLiteral().getRawType();
    Class<?> implementationType = implementedBy.value();

    // Make sure it's not the same type. TODO: Can we check for deeper cycles?
    if (implementationType == rawType) {
      throw errors.recursiveImplementationType().toException();
    }

    // Make sure implementationType extends type.
    if (!rawType.isAssignableFrom(implementationType)) {
      throw errors.notASubtype(implementationType, rawType).toException();
    }

    @SuppressWarnings("unchecked") // After the preceding check, this cast is safe.
    Class<? extends T> subclass = (Class<? extends T>) implementationType;

    // Look up the target binding.
    final Key<? extends T> targetKey = Key.get(subclass);
    Object source = rawType;
    FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source);
    factory.notify(errors); // causes the factory to initialize itself internally
    return new LinkedBindingImpl<T>(
        this,
        key,
        source,
        Scoping.<T>scope(key, this, factory, source, scoping),
        scoping,
        targetKey);
  }
private <T> BindingImpl<T> createImplementedByBinding(
      Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors)
      throws ErrorsException {
    Class<?> rawType = key.getTypeLiteral().getRawType();
    Class<?> implementationType = implementedBy.value();

    // Make sure it's not the same type. TODO: Can we check for deeper cycles?
    if (implementationType == rawType) {
      throw errors.recursiveImplementationType().toException();
    }

    // Make sure implementationType extends type.
    if (!rawType.isAssignableFrom(implementationType)) {
      throw errors.notASubtype(implementationType, rawType).toException();
    }

    @SuppressWarnings("unchecked") // After the preceding check, this cast is safe.
    Class<? extends T> subclass = (Class<? extends T>) implementationType;

    // Look up the target binding.
    final Key<? extends T> targetKey = Key.get(subclass);
    Object source = rawType;
    FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source);
    factory.notify(errors); // causes the factory to initialize itself internally
    return new LinkedBindingImpl<T>(
        this,
        key,
        source,
        Scoping.<T>scope(key, this, factory, source, scoping),
        scoping,
        targetKey);
  }
private < T > BindingImpl < T > createImplementedByBinding ( Key < T > key , Scoping scoping , ImplementedBy implementedBy , Errors errors ) throws ErrorsException { Class < ? > rawType = key . getTypeLiteral ( ) . getRawType ( ) ; Class < ? > implementationType = implementedBy . value ( ) ; // Make sure it's not the same type. TODO: Can we check for deeper cycles? if ( implementationType == rawType ) { throw errors . recursiveImplementationType ( ) . toException ( ) ; } // Make sure implementationType extends type. if ( ! rawType . isAssignableFrom ( implementationType ) ) { throw errors . notASubtype ( implementationType , rawType ) . toException ( ) ; } @ SuppressWarnings ( "unchecked" ) // After the preceding check, this cast is safe. Class < ? extends T > subclass = ( Class < ? extends T > ) implementationType ; // Look up the target binding. final Key < ? extends T > targetKey = Key . get ( subclass ) ; Object source = rawType ; FactoryProxy < T > factory = new FactoryProxy <> ( this , key , targetKey , source ) ; factory . notify ( errors ) ; // causes the factory to initialize itself internally return new LinkedBindingImpl < T > ( this , key , source , Scoping . < T > scope ( key , this , factory , source , scoping ) , scoping , targetKey ) ; }
Creates a binding for a type annotated with @ImplementedBy.
Creates a binding for a type annotated with