Sorry that I don't have Chinese input here.I have a super class A, and children classes B and C. All of them have their own fields.A| public a1, public a2, public a3B| b1, b2, b3C| c1, c2, c3
Now I want to copy the common fields of a1, a2, a3 from B to C, is there any simple way to implement this, or is there any pattern applicable? Thanks a lot.
Now I want to copy the common fields of a1, a2, a3 from B to C, is there any simple way to implement this, or is there any pattern applicable? Thanks a lot.
IllegalAccessException, NoSuchFieldException {
String[] names = new String[] { "a1", "a2", "a3" };
for (int i = 0; i <= names.length - 1; i++) {
this.getClass().getField(names[i])
.set(this, b.getClass().getField(names[i]).get(b));
}
}