Am 29.11.2011 20:23, schrieb Charles Oliver Nutter:
[...]
If you want to replace an incoming argument, you probably want to use
filterArguments like this:

// I always import static MethodHandles.* and MethodType.* to clean up code

MethodHandle handle =<get handle to System.setProperty>

// this line wraps a constant handle with a "drop", so it ignores the
String it is passed
MethodHandle replaceWithFoo = dropArguments(constant(String.class,
"foo"), 0, String.class);

// this line replaces the incoming property key with "foo", unconditionally
handle = filterArguments(handle, 0, replaceWithFoo);

arg... now I see... I always had the impression I have to use drop on handle, but I forgot that it works actually reverse... well reverse to what I would expect. Thanks, now it works in this variant.

Of course you can use a handle that actually processes the argument
and changes it into something else, like this version that upcases the
both strings on the way through:

MethodHandle upcase = lookup.findVirtual(String.class, "toUpperCase",
methodType(String.class);
handle = filterArguments(handle, 0, upcase, upcase);

That I managed. Only the version with the constant was missing.

It definitely takes a while to grok all the combinations of method
handle adapters, but once you get the hang of it you can do some
amazing things.

absolutely!

bye Jochen

--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org

--
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to