i try to use annotation to register settings for a Feature, but i cant reflect the setting field, what i did wrong, ty
this is Feature init, i want add settings
public Feature() {
try {
Class<SettingAnno> anno = SettingAnno.class;
for (Field field : this.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(anno)) {
Setting setting = (Setting) field.get(this);
this.settings.add(setting);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
but when i use Setting setting = (Setting) field.get(this);
, it actually will be set to 'null'
the Feature child:
public final class FeatureChild extends Feature {
@SettingAnno("setting1")
public final BooleanSetting setting1 = new BooleanSetting(true);
}
BoolenSetting is Setting child
this is the annotation
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SettingAnno {
String value();
}