我希望能够(用Java)编写如下内容:
public class A implements MagicallyConfigurable {
@configuration_source_type{"xml"}
@configuration_dir{"some/rel/path/"}
/* or maybe some other annotations specifying a db-based configuration etc. */
int length = 4 /* some kind of default */;
char c = '*' /* some kind of default */;
@do_not_configure
String title;
A(String title) {
/* possibly, but hopefully no need to, something like:
configure();
call here. */
this.title = title;
}
void goForIt() {
System.out.println(title);
for(int i=0; i < length; i++) {
System.out.print(c);
}
}
}
并使其按预期工作。也就是说,我需要根据配置初始化字段的唯一事情就是添加一些注释、实现接口并可能进行单个函数调用(但希望没有它)。
我确信这在理论上是可行的,问题是是否有现有的库/框架/附加组件/thingie 可以启用它。(也许 Apache commons.configuration 不知何故?以前没用过。)