Interface InstanceHandle<T>

  • Type Parameters:
    T -
    All Superinterfaces:
    AutoCloseable, jakarta.enterprise.inject.Instance.Handle<T>
    All Known Subinterfaces:
    ContextInstanceHandle<T>
    All Known Implementing Classes:
    ContextInstanceHandleImpl

    public interface InstanceHandle<T>
    extends AutoCloseable, jakarta.enterprise.inject.Instance.Handle<T>
    Represents an instance handle.
    Author:
    Martin Kouba
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void close()
      Delegates to destroy() if the handle does not represent a CDI contextual instance or if it represents a Dependent CDI contextual instance.
      default void destroy()
      Destroy the instance as defined by Contextual.destroy(Object, jakarta.enterprise.context.spi.CreationalContext).
      T get()  
      default InjectableBean<T> getBean()  
      default boolean isAvailable()  
      default T orElse​(T other)
      If an instance is available, returns the value, otherwise returns other.
    • Method Detail

      • get

        T get()
        Specified by:
        get in interface jakarta.enterprise.inject.Instance.Handle<T>
        Returns:
        an instance of T or null
      • isAvailable

        default boolean isAvailable()
        Returns:
        true if an instance is available, false otherwise
      • orElse

        default T orElse​(T other)
        If an instance is available, returns the value, otherwise returns other.
        Parameters:
        other -
        Returns:
        the instance if available, otherwise other
      • destroy

        default void destroy()
        Destroy the instance as defined by Contextual.destroy(Object, jakarta.enterprise.context.spi.CreationalContext). If this is a CDI contextual instance, it is also removed from the underlying context.
        Specified by:
        destroy in interface jakarta.enterprise.inject.Instance.Handle<T>
        See Also:
        AlterableContext.destroy(jakarta.enterprise.context.spi.Contextual)
      • getBean

        default InjectableBean<T> getBean()
        Specified by:
        getBean in interface jakarta.enterprise.inject.Instance.Handle<T>
        Returns:
        the injectable bean for a CDI contextual instance or null
      • close

        default void close()
        Delegates to destroy() if the handle does not represent a CDI contextual instance or if it represents a Dependent CDI contextual instance.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface jakarta.enterprise.inject.Instance.Handle<T>