title: how to compare two objects and find the fields/properties changed?
body: <p>I need to write some generic solution to find out what properties in two objects have changed and return the changed properties (not the value).</p>
  
  <pre><code>class Student {
      public String name;
      public Address address;
      public int age;
  }
  
  class Address {
      public String hno;
      public String street;
      public int pin;
  }
  
  public class Test {
      public static void main(String... arg) {
  
          Student s1 = new Student();
          s1.name = "Krishna";
          s1.age = 30;
          s1.address = new Address();
          s1.address.hno = "2-2-22";
          s1.address.street = "somewhere";
          s1.address.pin = 123;
  
          Student s2 = new Student();
          s2.name = "Krishna";
          s2.age = 20;
          s2.address = new Address();
          s2.address.hno = "1-1-11";
          s2.address.street = "nowhere";
          s2.address.pin = 123;
  
          List&lt;String&gt; = difference(s1, s2);
          // expected result
          // Student.age
          // Student.address.hno
          // Student.address.street
      }
  }
  </code></pre>
  
  <p>Can anyone please suggest some solution? </p>
  
  <p>PS</p>
  
  <p>Overriding equals/hashcode is not an option for me.</p>
  
  <p>I have written the below code but I am not sure how to identify if a type is complex (for example Address)</p>
  
  <pre><code>private static List&lt;String&gt; difference(Student s1, Student s2) throws IllegalArgumentException, IllegalAccessException {
  
          for(Field field: Student.class.getDeclaredFields()) {
              System.out.println(field.getName() + " " +field.get(s1).equals(field.get(s2)));
          }
          return null;
      }
  </code></pre>