Skip to main content

Error in an example of "Java Virtual Machine Support for Non-Java Languages"

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
vmonfort
Offline
Joined: 2011-07-27

In the example "Example.java" of the Java Virtual Machine Support for Non-Java Languages documentation, the following code is given:

    MethodHandle mh =
      callerClass.findStatic(
        Example.class,
        "IntegerOps.adder",
        MethodType.methodType(Integer.class, Integer.class, Integer.class));

    if (!dynMethodType.equals(mh.type())) {
      mh = mh.asType(dynMethodType);
    }

after doing some tests and having a look at the new Java documention, it seems that the code must be:

    MethodHandle mh =
      callerClass.findStatic(
       IntegerOps.class,
        "adder",
        MethodType.methodType(Integer.class, Integer.class, Integer.class));

    if (!dynMethodType.equals(mh.type())) {
      mh = mh.asType(dynMethodType);
    }

since the method "adder" is in the class IntegerOps.