Create Java method from a string?
<p>Is it possible in Java, to declare a method with a string instead of an identifier?</p>

<p>For example can I do something like the following:</p>

<pre><code>class Car{

     new Method("getFoo", {
          return 1+1;
     });
}

//Use it
Car car = new Car();
car.getFoo();
</code></pre>

<p>EDIT: I am adding a Purpose WHY I need this. In order to not hardcode method names when using Jersey and its UriBuilder, which requires a method name:
<a href="https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/UriBuilder.html" rel="nofollow">https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/UriBuilder.html</a></p>

<p>See path() method with signature:</p>

<pre><code> public abstract UriBuilder path(java.lang.Class resource,
                            java.lang.String method)
                     throws java.lang.IllegalArgumentException
</code></pre>

<p>So then I may just use string constants and not worry that the method name will ever be different from the string that I am passing to the path() method.</p>

<p>I hope my question is clear, if not - let me know and I can clarify it.</p>
