- java.lang.Object
-
- java.lang.invoke.CallSite
-
- java.lang.invoke.ConstantCallSite
-
public class ConstantCallSite extends CallSite
A ConstantCallSite is permanently bound to its initial target MethodHandle. Any call tosetTarget(MethodHandle)
will result in an UnsupportedOperationException.- Since:
- 1.7
-
-
Constructor Summary
Constructors Modifier Constructor Description ConstantCallSite(MethodHandle permanentTarget)
Create a ConstantCallSite with a target MethodHandle that cannot change.protected
ConstantCallSite(MethodType targetType, MethodHandle hook)
Create a ConstantCallSite and assign the hook MethodHandle's result to its permanent target.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodHandle
dynamicInvoker()
Return the target MethodHandle of this CallSite.MethodHandle
getTarget()
Return the target MethodHandle of this CallSite.void
setTarget(MethodHandle newTarget)
Throws UnsupportedOperationException as a ConstantCallSite is permanently bound to its initial target MethodHandle.
-
-
-
Constructor Detail
-
ConstantCallSite
public ConstantCallSite(MethodHandle permanentTarget)
Create a ConstantCallSite with a target MethodHandle that cannot change.- Parameters:
permanentTarget
- - the target MethodHandle to permanently associate with this CallSite.
-
ConstantCallSite
protected ConstantCallSite(MethodType targetType, MethodHandle hook) throws Throwable, WrongMethodTypeException, NullPointerException, ClassCastException
Create a ConstantCallSite and assign the hook MethodHandle's result to its permanent target. The hook MethodHandle is invoked as though by (@link MethodHandle#invoke(this)) and must return a MethodHandle that will be installed as the ConstantCallSite's target.The hook MethodHandle is required if the ConstantCallSite's target needs to have access to the ConstantCallSite instance. This is an action that user code cannot perform on its own.
The hook must return a MethodHandle that is exactly of type targetType.
Until the result of the hook has been installed in the ConstantCallSite, any call to getTarget() or dynamicInvoker() will throw an IllegalStateException. It is always valid to call type().
- Parameters:
targetType
- - the type of the ConstantCallSite's targethook
- - the hook handle, with signature (ConstantCallSite)MethodHandle- Throws:
Throwable
- anything thrown by the hook.WrongMethodTypeException
- if the hook has the wrong signature or returns a MethodHandle with the wrong signatureNullPointerException
- if the hook is null or returns nullClassCastException
- if the result of the hook is not a MethodHandle
-
-
Method Detail
-
dynamicInvoker
public final MethodHandle dynamicInvoker() throws IllegalStateException
Return the target MethodHandle of this CallSite.- Specified by:
dynamicInvoker
in classCallSite
- Returns:
- a MethodHandle that is equivalent to an invokedynamic instruction on this CallSite.
- Throws:
IllegalStateException
- - if the target has not yet been assigned in the ConstantCallSite constructor
-
getTarget
public final MethodHandle getTarget() throws IllegalStateException
Return the target MethodHandle of this CallSite. The target is defined as though it where a final field.- Specified by:
getTarget
in classCallSite
- Returns:
- the current target MethodHandle
- Throws:
IllegalStateException
- - if the target has not yet been assigned in the ConstantCallSite constructor
-
setTarget
public final void setTarget(MethodHandle newTarget)
Throws UnsupportedOperationException as a ConstantCallSite is permanently bound to its initial target MethodHandle.
-
-