<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 18, 2009, at 6:57 PM, Yehuda Katz wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I've pretty much achieved everything I was trying to do last night:&nbsp;<a href="http://gist.github.com/113717">http://gist.github.com/113717</a></blockquote><div><br></div>Congratulations!</div><div><br><blockquote type="cite"><div><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">Ideally, I'd like to be able to do something like:</span></div><div> <div><br></div><div><div>&nbsp;&nbsp; &nbsp;Object invoke(DynamicTester tester, Object... objects) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp;return target.invoke(tester, name, objects);</div><div>&nbsp;&nbsp; &nbsp;}</div><div><br></div><div>Where the original method could be methodNotFound(name, String... name) or whatever.</div> <div><br></div><div>Again, I'm relatively new to all this, so I'm pretty sure what I want to do is either a big no-no or a no-brainer.</div></div></div></blockquote></div><br><div>It's a common use case: &nbsp;You have an indy site with a specific type (e.g., (String)-&gt;String) and you want to route calls from there to a generic method. &nbsp;The way to make up the difference between method handles types (calling sequences) is to use one of MethodHandles.{convert,spread,collect}Arguments.<br></div><div><br></div><div>In your use case (as is common) there are two method handles in play, the ultimate target (the handle to methodNotFound), and the immediate target (your MethodMissingHandle object). &nbsp; Either (or both) might differ in their type from the call site's type. &nbsp;In that case, the difference must be made up with one of the *Arguments calls.</div><div><br></div><div>BTW, as a matter of style, if a class defines methods which are expected to be used&nbsp;via method handles, and&nbsp;by multiple clients, it's probably a good idea for the class to provide access to those methods in the form of method handles, whether or not it also provides them as directly callable (named) methods. &nbsp;E.g.:</div><div><br></div><div><span class="Apple-style-span" style="font-family: Monaco; line-height: 16px; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; "><div class="line" id="LC3" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; "><span class="kd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">public</span> <span class="kd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">class</span> <span class="nc" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(68, 85, 136); font-weight: bold; ">DynamicTester</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">{</span></div><div class="line" id="LC4" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; ">&nbsp;&nbsp;<span class="kd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">public</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">String</span> <span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 0, 0); font-weight: bold; ">methodNotFound</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">(</span><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">String</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">name</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">,</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">String</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">extra</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">)</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">{</span></div><div class="line" id="LC5" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; ">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">return</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">name</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">+</span> <span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">extra</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">;</span></div><div class="line" id="LC6" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; ">&nbsp;&nbsp;<span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">}</span></div><span class="Apple-style-span" style="font-family: Monaco; white-space: normal; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; "><span class="Apple-style-span" style="font-family: Monaco; line-height: 16px; white-space: normal; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; "><div class="line" id="LC6" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; "><b><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">  public static final </span></font><span class="Apple-style-span" style="font-weight: normal; "><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">MethodHandle</span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"> </span></font><span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 0, 0); font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">METHOD_NOT_FOUND</span></font></span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"> = ...;</span></font></span></span></b></div><div class="line" id="LC6" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; "><b><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">  // OR:</span></font></b></div><span class="Apple-style-span" style="font-family: Monaco; white-space: normal; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; "></pre></span></pre></span><span class="Apple-style-span" style="font-family: Monaco; line-height: 16px; white-space: normal; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; "><div class="line" id="LC6" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; "><b><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">  public </span></font><span class="Apple-style-span" style="font-weight: normal; line-height: 18px; "><span class="n" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">MethodHandle</span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"> </span></font><span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 0, 0); font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">methodNotFound</span></font></span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">(</span></font></span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">)</span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"> </span></font><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">{ return /*private*/&nbsp;<span class="Apple-style-span" style="color: rgb(153, 0, 0); ">METHOD_NOT_FOUND<span class="Apple-style-span" style="color: rgb(0, 0, 0); ">; }</span></span></span></font></span></span></b></div></pre></span></pre></span><div class="line" id="LC7" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; line-height: 1.4em; "><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">}</span></div></pre></span></div><div><br></div><div>-- John</div></body></html>