Class InvokeDynamicExamples
java.lang.Object
net.jrodolfo.java_evolution.java07.invokedynamic.InvokeDynamicExamples
Demonstrates Java 7
invokedynamic linkage support.
Ordinary Java source does not directly spell an invokedynamic
instruction. This example demonstrates the Java 7 linkage building blocks in
java.lang.invoke building blocks. Later Java features such as lambdas
can use this JVM linkage infrastructure, but they are not part of this Java
7 example.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCaptures mutable call-site behavior before and after retargeting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the method type associated with the bootstrap-linked call site.Attempts to retarget a mutable call site to an incompatible method type.invokeConstantCallSite(String prefix, String name) Creates a bootstrap-like constant call site and invokes it.static StringTarget used by the constant call-site example.static intIncompatible target used to demonstrate call-site type checks.static StringTarget used after mutable call-site retargeting.retargetMutableCallSite(String value) Demonstrates a mutable call site whose target changes at runtime.static StringTarget used before mutable call-site retargeting.
-
Constructor Details
-
InvokeDynamicExamples
public InvokeDynamicExamples()
-
-
Method Details
-
invokeConstantCallSite
Creates a bootstrap-like constant call site and invokes it.- Parameters:
prefix- greeting prefixname- name to greet- Returns:
- greeting produced through the call site's dynamic invoker
- Throws:
Throwable- when method-handle lookup or invocation fails
-
constantCallSiteType
Returns the method type associated with the bootstrap-linked call site.- Returns:
- method type exposed by the call site
- Throws:
NoSuchMethodException- when the target method cannot be foundIllegalAccessException- when the target method is not accessible
-
retargetMutableCallSite
Demonstrates a mutable call site whose target changes at runtime.- Parameters:
value- value to transform- Returns:
- results before and after retargeting
- Throws:
Throwable- when method-handle lookup or invocation fails
-
incompatibleTargetFailure
public WrongMethodTypeException incompatibleTargetFailure() throws NoSuchMethodException, IllegalAccessExceptionAttempts to retarget a mutable call site to an incompatible method type.- Returns:
- the exception raised by the call-site type check
- Throws:
NoSuchMethodException- when the target method cannot be foundIllegalAccessException- when the target method is not accessible
-
join
-
uppercase
-
lowercase
-
length
Incompatible target used to demonstrate call-site type checks.- Parameters:
value- value to measure- Returns:
- value length
-