title: Java: How can I access a class's field by a name stored in a variable?
body: <p>How can I set or get a field in a class whose name is dynamic and stored in a string variable?</p>
  
  <pre><code>public class Test {
  
      public String a1;
      public String a2;  
  
      public Test(String key) {
          this.key = 'found';  &lt;--- error
      } 
  
  }
  </code></pre>