title: Check type of primitive field
body: <p>I'm trying to determine the type of a field on an object. I don't know the type of the object when it is passed to me but I need to find fields which are <code>long</code>s. It is easy enough to distinguish the boxed <code>Long</code>s but the primitive <code>long</code> seems more difficult.</p>
  
  <p>I <em>can</em> make sure that the objects passed to me only have <code>Longs</code>, not the primitives, but I'd rather not. So what I have is:</p>
  
  <pre><code>for (Field f : o.getClass().getDeclaredFields()) {
      Class&lt;?&gt; clazz = f.getType();
      if (clazz.equals(Long.class)) {
          // found one -- I don't get here for primitive longs
      }
  }
  </code></pre>
  
  <p>A hacky way, which seems to work, is this:</p>
  
  <pre><code>for (Field f : o.getClass().getDeclaredFields()) {
      Class&lt;?&gt; clazz = f.getType();
      if (clazz.equals(Long.class) ||  clazz.getName().equals("long")) {
          // found one
      }
  }
  </code></pre>
  
  <p>I'd really like a cleaner way to do this if there is one. If there is no better way then I think that requiring the objects I receive to only use <code>Long</code> (not <code>long</code>) would be a better API.</p>
  
  <p>Any ideas?</p>