How to get hold of a method name without using magic strings
<p>In java is there any library to get the field name without using any magic strings, for example, for following class</p>

<pre><code>class User
{
int id;

int getId()
{
return id;
}

void setId(int id)
{
this.id = id;
}
}
</code></pre>

<p>Now what i want is something like this,</p>

<pre><code>String fieldName = Utility.getFieldName(User.getId());
</code></pre>

<p>this should return text "id" </p>

<p>I know this is not achievable by usual means, but I am thinking if it can be done by wrapping the User class with a dynamic proxy (so this would be more like </p>

<pre><code>String fieldName = Utility.getFieldName(Utility.createProxy&lt;User&gt;().getId());
</code></pre>

<p>) and intercepting the method call and obtaining method name from stack, and use some thread joins to look it like a simple method call when looked at the Utility class. Does anyone knows if there is any library to do this type of operation?</p>
