org.springframework.beans.factory

## 接口 ObjectProvider<T>

- 所有超级接口:
    ObjectFactory<T>

      public interface ObjectProvider<T>
      extends ObjectFactory<T>

  A variant of `ObjectFactory` designed specifically for injection points, allowing for programmatic optionality and lenient not-unique handling.
  从以下版本开始:
    4.3
  作者:
    Juergen Hoeller

- - ### 方法概要

    所有方法 实例方法 抽象方法 默认方法
    限定符和类型 | 方法和说明
    --- | ---
    `T` | `getIfAvailable()` Return an instance (possibly shared or independent) of the object managed by this factory.
    `default T` | `getIfAvailable(Supplier<T> defaultSupplier)` Return an instance (possibly shared or independent) of the object managed by this factory.
    `T` | `getIfUnique()` Return an instance (possibly shared or independent) of the object managed by this factory.
    `default T` | `getIfUnique(Supplier<T> defaultSupplier)` Return an instance (possibly shared or independent) of the object managed by this factory.
    `T` | `getObject(Object... args)` Return an instance (possibly shared or independent) of the object managed by this factory.
    `default void` | `ifAvailable(Consumer<T> dependencyConsumer)` Consume an instance (possibly shared or independent) of the object managed by this factory, if available.
    `default void` | `ifUnique(Consumer<T> dependencyConsumer)` Consume an instance (possibly shared or independent) of the object managed by this factory, if unique.

    - ### 从接口继承的方法 org.springframework.beans.factory.ObjectFactory

      `getObject`

- - ### 方法详细资料

    - #### getObject

          T getObject(Object... args)
               throws BeansException

      Return an instance (possibly shared or independent) of the object managed by this factory.

      Allows for specifying explicit construction arguments, along the lines of `BeanFactory.getBean(String, Object...)`.

      参数:
        `args` - arguments to use when creating a corresponding instance
      返回:
        an instance of the bean
      抛出:
        `BeansException` - in case of creation errors
      另请参阅:
        `ObjectFactory.getObject()`

    - #### getIfAvailable

          @Nullable
          T getIfAvailable()
                               throws BeansException

      Return an instance (possibly shared or independent) of the object managed by this factory.
      返回:
        an instance of the bean, or `null` if not available
      抛出:
        `BeansException` - in case of creation errors
      另请参阅:
        `ObjectFactory.getObject()`

    - #### getIfAvailable

          default T getIfAvailable(Supplier<T> defaultSupplier)
                            throws BeansException

      Return an instance (possibly shared or independent) of the object managed by this factory.
      参数:
        `defaultSupplier` - a callback for supplying a default object if none is present in the factory
      返回:
        an instance of the bean, or the supplied default object if no such bean is available
      抛出:
        `BeansException` - in case of creation errors
      从以下版本开始:
        5.0
      另请参阅:
        `getIfAvailable()`

    - #### ifAvailable

          default void ifAvailable(Consumer<T> dependencyConsumer)
                            throws BeansException

      Consume an instance (possibly shared or independent) of the object managed by this factory, if available.
      参数:
        `dependencyConsumer` - a callback for processing the target object if available (not called otherwise)
      抛出:
        `BeansException` - in case of creation errors
      从以下版本开始:
        5.0
      另请参阅:
        `getIfAvailable()`

    - #### getIfUnique

          @Nullable
          T getIfUnique()
                            throws BeansException

      Return an instance (possibly shared or independent) of the object managed by this factory.
      返回:
        an instance of the bean, or `null` if not available or not unique (i.e. multiple candidates found with none marked as primary)
      抛出:
        `BeansException` - in case of creation errors
      另请参阅:
        `ObjectFactory.getObject()`

    - #### getIfUnique

          default T getIfUnique(Supplier<T> defaultSupplier)
                         throws BeansException

      Return an instance (possibly shared or independent) of the object managed by this factory.
      参数:
        `defaultSupplier` - a callback for supplying a default object if no unique candidate is present in the factory
      返回:
        an instance of the bean, or the supplied default object if no such bean is available or if it is not unique in the factory (i.e. multiple candidates found with none marked as primary)
      抛出:
        `BeansException` - in case of creation errors
      从以下版本开始:
        5.0
      另请参阅:
        `getIfUnique()`

    - #### ifUnique

          default void ifUnique(Consumer<T> dependencyConsumer)
                         throws BeansException

      Consume an instance (possibly shared or independent) of the object managed by this factory, if unique.
      参数:
        `dependencyConsumer` - a callback for processing the target object if unique (not called otherwise)
      抛出:
        `BeansException` - in case of creation errors
      从以下版本开始:
        5.0
      另请参阅:
        `getIfAvailable()`