Module java.base
Package java.lang.invoke

Interface ConstantGroup

  • All Superinterfaces:
    Collection<Object>, Iterable<Object>, List<Object>
    All Known Subinterfaces:
    BootstrapCallInfo<T>
    All Known Implementing Classes:
    ConstantGroup.AbstractImpl


    public interface ConstantGroup
    extends List<Object>
    An ordered list of constants, some of which may not yet be linked. This type is used by BootstrapCallInfo to represent the sequence of bootstrap arguments associated with a bootstrap method, without forcing their immediate resolution.

    In order to peek at a constant without necessarily resolving it, use the normal get method inherited from List. This method will never throw a resolution error but may return the empty NOT_PRESENT. If you need to resolve the constant, use the resolve(int) method, but be prepared to catch any LinkageError arising from the resolution process, if the constant is not already resolved.

    To iterate through the constants, resolving as you go, use the view method resolving().

    Since:
    1.10
    • Field Detail

      • NOT_PRESENT

        static final Object NOT_PRESENT
        Sentinel value returned by get(int) if a requested constant is not available, either because it has not yet been resolved, or because resolution was attempted but caused an error.
    • Method Detail

      • get

        Object get​(int index)
        Returns the selected constant, or a sentinel value if there is none available. If the argument cannot be resolved, the sentinel will be returned. If the argument can (perhaps) be resolved, but has not yet been resolved, then the sentinel may be returned, at the implementation's discretion. To force resolution (and a possible exception), call resolve(int).
        Specified by:
        get in interface List<Object>
        Parameters:
        index - the selected constant
        Returns:
        the static argument, if available, else the sentinel value NOT_PRESENT.
      • get

        default Object get​(int index,
                           Object ifNotPresent)
        Returns the selected constant, or the given sentinel value if there is none available.
        Parameters:
        index - which constant to select
        ifNotPresent - the sentinel value to return if the constant is not present
        Returns:
        the selected constant
      • resolve

        Object resolve​(int index)
                throws LinkageError
        
        Returns the selected constant, resolving it if necessary.
        Parameters:
        index - which constant to select
        Returns:
        the selected constant
        Throws:
        LinkageError - if the static argument needs resolution and cannot be resolved
      • resolving

        default Iterable<Object> resolving​()
        Iterate over this list forcing resolution at each step, as if by calling resolve(int) instead of get(int)
        Returns:
        an object ready to iterate over the list, resolving as it goes
      • subList

        default ConstantGroup subList​(int start,
                                      int end)
        Create a view on a sub-list of this list.
        Specified by:
        subList in interface List<Object>
        Parameters:
        start - the index to begin the view
        end - the index to end the view
        Returns:
        a view on the selected sub-list
      • copyOutArguments

        default void copyOutArguments​(int start,
                                      int end,
                                      Object[] buf,
                                      int pos,
                                      boolean resolve,
                                      Object ifNotPresent)
                               throws LinkageError
        
        Copy a sequence of static arguments for this call into a given buffer. This is equivalent to end-offset separate calls to argument, for each index in the range from offset up to but not including end. If
        Parameters:
        start - index of first argument to retrieve
        end - limiting index of arguments to retrieve
        buf - array to receive the requested arguments
        pos - position in the array to offset storing the arguments
        resolve - whether to force resolution
        ifNotPresent - sentinel value to store if resolve is false and the argument is not available
        Throws:
        LinkageError - if resolve is true and an argument cannot be resolved