title: Java reflection: get class of field
body: <p>I have a method that requires something like <code>Double.class</code> as one of its inputs;</p>
  
  <p>e.g. </p>
  
  <pre><code>someOutput = SomeObj.someMethod("parameter",Double.class);
  </code></pre>
  
  <p>I have another class that has a bunch of fields of different datatypes that I'd like to feed as input to this method  in stead of explicitly writing <code>Double.class</code> of <code>Integer.class</code> etc etc.</p>
  
  <p>I know this involves java reflection, but I'm not quite sure how to do what I want.  I'm trying something like this but it isn't working:</p>
  
  <pre><code>for(Field field : Class.forName(MyClassWithLotsOfFields.class.getCanonicalName()).getFields()){ 
     someOutput = SomeObj.someMethod("parameter",field.getClass());
    //Do more stuff here...
  }   
  </code></pre>
  
  <p>but <code>field.getClass()</code> is not giving me the actual class of the field from <code>MyClassWithLotsOfFields</code> but instead <code>java.lang.reflect.Field</code></p>
  
  <p>any ideas for how to do what I want?</p>