title: Get the strongly typed property value from object in Java
body: <p>What is the best way to get a strongly typed value of a property, using the property name as string, of an object in Java.</p>
  
  <p>For eg: A Person class with age field as an integer, say 21. If the following statement has to return integer 21 for age field, then what should be the implementation of get method? [Note: 21 is to be returned as integer]</p>
  
  <pre><code>ObjectUtils.get(person, "age");
  </code></pre>
  
  <p>Sample method header </p>
  
  <pre><code>public static &lt;E&gt; E get(Object object, String fieldName);
  </code></pre>
  
  <p>One way is to get the type of the field and type cast explicitly. </p>
  
  <p>Other way is to use <strong>getProperty</strong> method in <strong>BeanUtils</strong> class (Apache commons library). But, the limitation is that it returns only string, but not the strongly typed value.</p>
  
  <p>Is there any better approach or library utility available to achieve this?</p>