Sometimes I need to test which class has declared some variable(s), is there another way how to test that, if concrete class contains variable with some name
try {
testLocalVariable = (String) (this.getClass().getDeclaredField("testVariable").get(this));
} catch (NoSuchFieldException ex) {
} catch (SecurityException ex) {
} catch (IllegalArgumentException ex) {
} catch (IllegalAccessException ex) {
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…