Have any class such as
public class Example {
public String pub;
protected String prot;
}
But in class which try to get public fields I see prot
field as public
. code of getting field:
public static List<Field> getPublicFields(Class targetClass) {
List<Field> result = new ArrayList<>();
result = Arrays.asList(targetClass.getFields());
for (int i = 0; i < result.size(); i++) {
Field currentField = result.get(i);
int modifiers = currentField.getModifiers();
if (Modifier.isStatic(modifiers) ||
currentField.isSynthetic() ||
!Modifier.isPublic(modifiers)) {
result.remove(i);
i--;
continue;
}
}
return result;
}
What am I write incorrect?
Aucun commentaire:
Enregistrer un commentaire