You can check org.apache.commons.lang.builder.EqualsBuilder, which will save you a lot of this problem if you want to make the field by comparing the fields.
org.apache.commons.lang.builder.EqualsBuilder.reflectionEquals(Object, Object)
If you want to compare the fields yourself, check out java.lang.Class.getDeclaredFields() , which will provide you with all the fields, including non-public fields.
Use f.get(qa).equals(f.get(qa4)) compare field values. Currently you are actually comparing field instances, not values.
source share