title: Java - how to extract the value of fields from another class
body: <p>I am trying to get all the fields and values from another read-only class, and write them into a file, how to get the values of fields?</p>
  <p>The class is read-only, and don't have getters:</p>
  <pre class="lang-java prettyprint-override"><code>  public class colorConstants {
      public static final String BLUE = &quot;blue&quot;;
      public static final String RED = &quot;red&quot;;
      public static final String YELLOW = &quot;yellow&quot;;
      ...
      
      public colorConstants() {}
    }
  </code></pre>
  <p>In another class:</p>
  <pre class="lang-java prettyprint-override"><code>Field[] fields = colorConstants.class.getFields();
  for(Field : fields) {
    String fieldName = fieldName;
    
    //how to get the value of each field
    String value = fieldName.get()?
  }
  </code></pre>