Module jakarta.cdi

Interface Instance.Handle<T>

  • Type Parameters:
    T - the required bean type
    All Superinterfaces:
    java.lang.AutoCloseable
    Enclosing interface:
    Instance<T>

    public static interface Instance.Handle<T>
    extends java.lang.AutoCloseable
    This interface represents a contextual reference handle.

    Allows to inspect the metadata of the relevant bean before resolving its contextual reference and also to destroy the underlying contextual instance.

    Author:
    Matej Novotny
    • Method Detail

      • get

        T get()
        The contextual reference is obtained lazily, i.e. when first needed.
        Returns:
        the contextual reference
        Throws:
        java.lang.IllegalStateException - If the producing Instance does not exist
        java.lang.IllegalStateException - If invoked on Instance.Handle that previously successfully destroyed its underlying contextual reference
        See Also:
        Provider.get()
      • getBean

        Bean<T> getBean()
        Returns:
        the bean metadata
      • destroy

        void destroy()
        Destroy the contextual instance. It's a no-op if:
        • called multiple times
        • if the producing Instance does not exist
        • if the handle does not hold a contextual reference, i.e. get() was never called
        See Also:
        Instance.destroy(Object)
      • close

        void close()
        Delegates to destroy().
        Specified by:
        close in interface java.lang.AutoCloseable