How do I use the new @BootstrapMethod annotation?
assembling signals
assembling.signals at yandex.ru
Fri Nov 12 07:17:10 PST 2010
Hello!
Sorry, but I seem not to understand the description of @BootstrapMethod javadoc.
I declare a class with a static method (which returns a CallSite).
The class from which InvokeDynamic is performed is annotated with the new annotation.
Error is: java.lang.IllegalStateException: no bootstrap method found for invokedynamic.
Please help!
= = = = = = = = = =
CODE
= = = = = = = = = =
import java.dyn.*;
@BootstrapMethod(value = _InvokeDynamic.Bootstrap.class, name = "bootstrap")
public class _InvokeDynamic {
public final static class Bootstrap {
public static CallSite bootstrap(Class<?> declaring, String name, MethodType type) {
CallSite cs = new CallSite();
System.out.println(declaring + "." + name + " : " + type);
cs.setTarget(mhNormal);
return cs;
}
}
private final static MethodHandle mhNormal;
public static int staticMethod(int i1, int i2) {
return i1 + i2;
}
static {
try {
mhNormal = MethodHandles.lookup().findStatic(
_InvokeDynamic.class, "staticMethod",
MethodType.methodType(int.class, int.class, int.class));
} catch (Exception ex) {
throw new Error(ex);
}
}
private static void doDynSyntaxUsual()
throws Throwable {
int x;
x = (int) InvokeDynamic.ANY((int) -1, (int) +2);
System.out.println(x);
}
public static void main(String... args)
throws Throwable {
doDynSyntaxUsual();
}
}
= = = = = = = = = =
OUTPUT
= = = = = = = = = =
Exception in thread "main" java.lang.IllegalStateException: no bootstrap method found for invokedynamic
at _InvokeDynamic.doDynSyntaxUsual(_InvokeDynamic.java:40)
at _InvokeDynamic.main(_InvokeDynamic.java:46)
More information about the mlvm-dev
mailing list