Spec-Zone .ru
спецификации, руководства, описания, API
Please note that the specifications and other information contained herein are not final and are subject to change. The information is being made available to you solely for purpose of evaluation.

Java™ Platform
Standard Ed. 7

DRAFT ea-b118

java.dyn
Class InvokeDynamic

java.lang.Object
  extended by java.dyn.InvokeDynamic

public final class InvokeDynamic
extends Object

InvokeDynamic is a class with neither methods nor instances, which serves only as a syntactic marker in Java source code for an invokedynamic instruction. (See the package information for specifics on this instruction.)

The invokedynamic instruction is incomplete without a target method. The target method is a property of the reified call site object which is linked to each active invokedynamic instruction. The call site object is initially produced by a bootstrap method associated with the class whose bytecodes include the dynamic call site.

The type InvokeDynamic has no particular meaning as a class or interface supertype, or an object type; it can never be instantiated. Logically, it denotes a source of all dynamically typed methods. It may be viewed as a pure syntactic marker of static calls. It may be imported for ease of use.

Here are some examples:


@BootstrapMethod(value=Here.class, name="bootstrapDynamic")
static void example() throws Throwable {
    Object x; String s; int i;
    x = InvokeDynamic.greet("world"); // greet(Ljava/lang/String;)Ljava/lang/Object;
    s = (String) InvokeDynamic.hail(x); // hail(Ljava/lang/Object;)Ljava/lang/String;
    InvokeDynamic.cogito(); // cogito()V
    i = (int) InvokeDynamic.#"op:+"(2, 3); // "op:+"(II)I
}
static MethodHandle bootstrapDynamic(Class caller, String name, MethodType type) { ... }
Each of the above calls generates a single invokedynamic instruction with the name-and-type descriptors indicated in the comments.

The argument types are taken directly from the actual arguments, while the return type corresponds to the target of the assignment. (Currently, the return type must be given as a false type parameter. This type parameter is an irregular use of the generic type syntax, and is likely to change in favor of a convention based on target typing.)

The final example uses a special syntax for uttering non-Java names. Any name legal to the JVM may be given between the double quotes.

None of these calls is complete without a bootstrap method, which must be declared for the enclosing class or method.


Method Summary
Modifier and Type Method and Description
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 


Java™ Platform
Standard Ed. 7

DRAFT ea-b118

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 1993, 2010, Oracle Corporation. All rights reserved.
DRAFT ea-b118

Scripting on this page tracks web page traffic, but does not change the content in any way.