If you are experimenting with the OpenJDK JDK7 bundles, you might have noticed 
that this syntax:
  mh.<int>invokeExact(x)
has changed to this:
  (int) mh.invokeExact(x)

Note on void:  There is no (void) cast in Java, but to get a void call, use a 
method call expression as a statement.  Conversely, to accept and discard a 
non-void result, assign it to an unused temporary variable.
  {mh.invokeExact();}  // ()V
  {int junk = (int) mh.invokeExact();}  // ()I

If you use the old syntax, you'll get a warning guiding you toward the new 
syntax:

  foo.java:22: warning: change obsolete notation for MethodHandle invocations 
from x.<T>invoke(y) to (T)x.invoke(y)
    s = mh.<String>invoke("daddy",'d','n');   //this works but gets warning

But, if you change the syntax as indicated, you might run into bug 6991980, 
which appeared in javac along with the syntax change and the warning.  The bug 
will cause the invocation to ignore the indicated return type (int or String 
above) and retain the default, plain Object.  The code will compile but will 
fail to execute as expected, causing an exception like this:

  Exception: java.dyn.WrongMethodTypeException: (CC)Ljava/lang/String; cannot 
be called as (Ljava/lang/String;CC)Ljava/lang/Object;

We will push the fix to 6991980 as quickly as possible, so that non-Object 
calls in the new syntax will work as specified.  In the meantime, please 
disregard the warnings above or treat them as tasks "to do later".

Later in the JDK7 engineering cycle, well before FCS, we will change the 
behavior of javac to upgrade the warnings to errors, and require users to adopt 
the new syntax.

-- John
_______________________________________________
mlvm-dev mailing list
mlvm-dev@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to