title: How can I make a copy of object via Reflection API?
body: <p>I want to create copy of object via <code>Reflection API</code>. Here is my code:</p>
  
  <pre><code>private &lt;T&gt; T copy(T entity) throws IllegalAccessException, InstantiationException {
      List&lt;Field&gt; fields = new ArrayList&lt;Field&gt;();
      Field[] retrievedFields = entity.getClass().getDeclaredFields();
      for (Field field : retrievedFields) {
          fields.add(field);
      }
      T newEntity = (T) entity.getClass().newInstance();
      for (Field field : fields) {
          field.setAccessible(true);
          field.set(newEntity, field.get(entity));
      }
      return newEntity;
  }
  </code></pre>
  
  <p>But I don't know how to get values of fields.</p>