Java .properties files as strongly typed classes

后端 未结 8 1186
小蘑菇
小蘑菇 2021-01-02 14:50

Is there way to get properties files as strongly typed classes? I guess there are code generators but doing it with annotations would be much cooler.

What I mean is;

8条回答
  •  死守一世寂寞
    2021-01-02 15:22

    If you want to do it statically, its a code generation problem that may be solved quite easily (for each item in file, produce a new getXXX method).

    But if you want this at runtime, then you have the problem of having your code referencing method that did not exists at compile time; I don't think it can be done.

    (Note that if you are looking for a project idead, the reverse, having an interface with accessor method and annotation, and an implementation generated at runtime, that relies on the annotated methods, can be done.)

提交回复
热议问题