title: Copying one class's fields into another class's identical fields
body: <p>I have this question. But it will be difficult for me to explain as I don't know exact terms to use. Hope someone will understand. I'll try to discribe to the best i can. I feel like this is much related to <code>parsing</code></p>
  
  <p>Say there are two classes. And in both classes I have some variables, say strings (just for simplicity, variable type can be any), which have <strong>similar names</strong>.</p>
  
  <pre><code>Eg:
      class ClassA{
          String x,y,z;
      }
  
      class ClassB{
          String x,y,z;
      }
  </code></pre>
  
  <p>Now, what i need is, i need to copy the value of one class's variable values to other classes corresponding variable.</p>
  
  <pre><code>Eg:
      ClassA aa=new ClassA();
      ClassB bb=new ClassB();
      //set bb's variables
      aa.x=bb.x;
      aa.y=bb.y;
      aa.z=bb.z;
  </code></pre>
  
  <p>like that.</p>
  
  <p>But please note that what i need is not the above method. I hope there will be a way to write a simple method, so that it will identify the relevent variable by the name passed to it. Then it will do the value assignment accordingly.</p>
  
  <p>My imagined method is like this,</p>
  
  <pre><code>void assign(String val){        
      // aa.&lt;val&gt;=val
  }
  </code></pre>
  
  <p>For example if you pass <code>bb.x</code> to <code>assign(...)</code> method, then it will do <code>aa.x=bb.x</code> assignment.</p>
  
  <p>Hope this is clear enough. There must be a better way to explain this. If someone know it please edit the post(+title) to make it more clear (But save my idea)..</p>
  
  <p>Please let me know if there's a way to achieve this.</p>
  
  <p>Thanks!</p>