How do I use the new @BootstrapMethod annotation?
Rémi Forax
forax at univ-mlv.fr
Fri Nov 12 08:50:08 PST 2010
Le 12/11/2010 16:17, assembling signals a écrit :
> 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!
>
javac embeded in latest jdk7 beta binaries doesn't support @BootstrapMethod.
Rémi
> = = = = = = = = = =
> 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)
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
More information about the mlvm-dev
mailing list