On Jun 14, 2011, at 5:21 PM, Attila Szegedi wrote:
> Thanks for the clarification, John. I'll go with asFixedArity().
Great! BTW, this little method got into the API "by the skin of its teeth".
Here's an interesting related exercise: If I have a variable-arity method
handle (like #Arrays.asList), how do we convert it to a spreader with more
fixed arguments?
MethodHandle mh = #Arrays.asList;
mh.invoke("foo", "bar"); //=> [foo, bar]
mh.invoke("foo", "bar", "baz"); //=> [foo, bar, baz]
MethodHandle mhFix1Fail = mh.asType(genericMethodType(1,
true)).asVarargsCollector(Object[].class);
mhFix1Fail.invoke("foo", "bar"); //=> [foo, [Ljava.lang.Object;@746d23]
mhFix1Fail.invoke("foo", "bar", "baz"); //=> [foo,
[Ljava.lang.Object;@746d23]
MethodHandle mhFix1 = (???);
mhFix1.invoke("foo", "bar"); //=> [foo, bar]
mhFix1.invoke("foo", "bar", "baz"); //=> [foo, bar, baz]
It would be analogous to this Lisp (Scheme) code:
(define mh list)
(define mhFix1 (lambda (x . xs) (apply mh x xs)))
I don't think there's a unique minimal way to do this in the present API. But
the Cookbook probably needs an example.
> Super excited as for the first time in history, Dynalink will get down to 0
> failing testcases as OpenJDK bugs making them fail got squashed, yay!
I'm super excited too. (Also super tired. Looking forward to a nice rest at
the Summit! :-) )
By the way, for an example of a really crunchy MH graph, see the second hunk in
this diff:
http://hg.openjdk.java.net/mlvm/mlvm/jdk/diff/af9f1edb308f/meth-unittests.patch
This didn't used to work just a few weeks ago...
-- John
_______________________________________________
mlvm-dev mailing list
[email protected]
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev