Module jdk.dynalink
Package jdk.dynalink

Class NamedOperation

java.lang.Object
jdk.dynalink.NamedOperation
All Implemented Interfaces:
Operation

public final class NamedOperation extends Object implements Operation
Operation that associates a name with another operation. Typically used with operations that normally take a name or an index to bind them to a fixed name. E.g.
     new NamedOperation(
         new NamespaceOperation(
             StandardOperation.GET,
             StandardNamespace.PROPERTY),
         "color")
 
will be a named operation for getting the property named "color" on the object it is applied to, and
     new NamedOperation(
         new NamespaceOperation(
             StandardOperation.GET,
             StandardNamespace.ELEMENT),
         3)
 
will be a named operation for getting the element at index 3 from the collection it is applied to ("name" in this context is akin to "address" and encompasses both textual names, numeric indices, or any other kinds of addressing that linkers can understand). In these cases, the expected signature of the call site for the operation will change to no longer include the name parameter. Specifically, the documentation for all StandardOperation members describes how they are affected by being incorporated into a named operation.

While NamedOperation can be constructed directly, it is often convenient to use the Operation.named(Object) factory method instead, e.g.:

    StandardOperation.GET
        .withNamespace(StandardNamespace.ELEMENT),
        .named(3)
     )
 

Even though NamedOperation is most often used with NamespaceOperation as its base, it can have other operations as its base too (except another named operation). Specifically, StandardOperation.CALL as well as StandardOperation.NEW can both be used with NamedOperation directly. The contract for these operations is such that when they are used as named operations, their name is only used for diagnostic messages, usually containing the textual representation of the source expression that retrieved the callee, e.g. StandardOperation.CALL.named("window.open").

Since:
9