I have Class A and Class B
In Class A I have some fields
private String name;
private String address;
private String phoneNo;
Class B I have some fields too
private String name;
private String city;
private String phoneNo;
In my main Class I get fields from both classes
A a = new A();
B b = new B();
Field[] fieldsFromA = a.getClass().getDeclaredFields();
Field[] fieldsFromB = b.getClass().getDeclaredFields();
I would like to have another Field[ ] where I can store fields that both exists in Class A and B
in ths example it would be name and phoneNo
is there a simple way to do that ?
I was thinking of doing a double for loop to filter out the same fields and then add them into the array but there are cases that Class A may contain more fields than Class B or vise versa which may lead me to miss out some...