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
Interface MethodHandleProvider

All Known Implementing Classes:
CallSite, ConstantCallSite, MethodHandle

public interface MethodHandleProvider

An interface for an object to provide a target method handle to a invokedynamic instruction. There are many function-like objects in various Java APIs. This interface provides a standard way for such function-like objects to be bound to a dynamic call site, by providing a view of their behavior in the form of a low-level method handle.

The type MethodHandle is a concrete class whose implementation hierarchy (if any) may be tightly coupled to the underlying JVM implementation. It cannot also serve as a base type for user-defined functional APIs. For this reason, MethodHandle cannot be subclassed to add new behavior to method handles. But this interface can be used to provide a link between a user-defined function and the invokedynamic instruction and the method handle API.


Method Summary
Modifier and Type Method and Description
 MethodHandle asMethodHandle()
          Produce a method handle which will serve as a behavioral proxy for the current object.
 MethodHandle asMethodHandle(MethodType type)
          Produce a method handle of a given type which will serve as a behavioral proxy for the current object.
 

Method Detail

asMethodHandle

MethodHandle asMethodHandle()
Produce a method handle which will serve as a behavioral proxy for the current object. The type and invocation behavior of the proxy method handle are user-defined, and should have some relation to the intended meaning of the original object itself.

The current object may have a changeable behavior. For example, CallSite has a setTarget method which changes its invocation. In such a case, it is incorrect for asMethodHandle to return a method handle whose behavior may diverge from that of the current object. Rather, the returned method handle must stably and permanently access the behavior of the current object, even if that behavior is changeable.

The reference identity of the proxy method handle is not guaranteed to have any particular relation to the reference identity of the object. In particular, several objects with the same intended meaning could share a common method handle, or the same object could return different method handles at different times. In the latter case, the different method handles should have the same type and invocation behavior, and be usable from any thread at any time. In particular, if a MethodHandleProvider is bound to an invokedynamic call site, the proxy method handle extracted at the time of binding will be used for an unlimited time, until the call site is rebound.

The type MethodHandle itself implements MethodHandleProvider, and for this method simply returns this.


asMethodHandle

MethodHandle asMethodHandle(MethodType type)
                            throws WrongMethodTypeException
Produce a method handle of a given type which will serve as a behavioral proxy for the current object. As for the no-argument version asMethodHandle(), the invocation behavior of the proxy method handle is user-defined. But the type must be the given type, or else a WrongMethodTypeException must be thrown.

If the current object somehow represents a variadic or overloaded behavior, the method handle returned for a given type might represent only a subset of the current object's repertoire of behaviors, which correspond to that type.

Throws:
WrongMethodTypeException

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.