title: How to get a string field value via reflection?
body: <p>I have this method that returns a list of Fields objects that are of String type. </p>
  
  <pre><code>    public static List&lt;Field&gt; getStringFields(Class&lt;?&gt; clazz) {
          List&lt;Field&gt; toReturn = new ArrayList&lt;Field&gt;();
  
          Field[] allFields = clazz.getDeclaredFields();
  
          for (Field f : allFields) {
              Class&lt;?&gt; type = f.getType();
              if (type == String.class) {
                  stringFields.add(f);
              }
          }
  
          return stringFields;
      }
  </code></pre>
  
  <p>And this method, that should captalize all the string fields:</p>
  
  <pre><code>public void capitalizeStringFields() {
      List&lt;Field&gt; stringFieldsToCapitalize = Utils.getStringFields(someClass.class);
      try {
          for (Field field : stringFieldsToCapitalize) {
              field.set(this, field.get(this).toString().toUpperCase());
          }
      } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The problem is: the "field.set(...)" is not working. It supposed to capitalize the value and set it as the new value for that field, but it's not working... Any idea of how can I solve this? (PS: In the real code the "someClass.class" is set as the real class name...)</p>
  
  <p>The error being generated is IllegalArgumentException in the field.get(this) method (insde the field.set method).</p>