How to get a Method instance for call stack element *without* arg signature?
<p><em>Disclaimer: I have 10 years' experience programming, but 8 of which is in PHP (loosely typed) -- I have been using Java now for 4 days</em> :)</p>

<p>In java, I need to get the value of an annotation for a method in the call stack. As far as I can tell, I do this with the Method object. From the call stack, I have retrieved the names of the class and method (strings). This is the (abbreviated) code that I am using...</p>

<p><strong>Calling Method:</strong></p>

<pre><code>public class myClass
{
   @Path( "some/path/value" )
   public void myMethod( String someArg ) { ... }
}
</code></pre>

<p><strong>Retrieval Code:</strong></p>

<pre><code>StackTraceElement[] trace = Thread.currentThread().getStackTrace();
String callingMethodName = trace[depth].getMethodName();
String callingClassName = trace[depth].getClassName();

Class[] signature = new Class[1];
signature[0] = String.class;

Class callingClass = Class.forName( callingClassName );
Method callingMethod = callingClass.getMethod( callingMethodName, signature );
Path annotation = callingMethod.getAnnotation( Path.class );
</code></pre>

<p>This works like a charm, successfully returning the value of the @Path annotation (<code>"some/path/value"</code>)</p>

<p>However, if you notice, I had to supply a signature of the method I was looking for. As you can see in the class code, there is only 1 method with that name, so, theoretically, the signature of the method should be irrelevant, right? As far as I can tell from various docs/blogs/examples, I should be able to call <code>getMethod( )</code> with either no 2nd argument, or with <code>null</code> for the 2nd argument, but if I use the following:</p>

<pre><code>Class callingClass = Class.forName( callingClassName );
Method callingMethod = callingClass.getMethod( callingMethodName );
</code></pre>

<p>Or even:</p>

<pre><code>Class callingClass = Class.forName( callingClassName );
Method callingMethod = callingClass.getMethod( callingMethodName, null );
</code></pre>

<p>I get a <code>NoSuchMethodException</code>. Am I doing something wrong here? Should I be taking a different approach altogether?</p>

<p>In this particular situation, the calling class/method never uses polymorphism so there is only ever 1 signature. However, said signature is not known (unless that can also be determined by data available/derivable from <code>Thread.currentThread( )</code>), so I need a way to get a Method object without knowing the signature.</p>
