Lucia wrote:
I'd like store all constants in my java-Application in an XML-file.
e.g.
<constant>
<name>con</name>
<type>long</type>
<value>10</value>
</constant>
After starting the application, the java class should be able to
create a variable with the name, the type and the value.
In this example, the java class should call the line at runtime:
long con = 10;
Has anyone an idea?
In full generality: impossible. You could set the values via the reflection
API, but you'd still have the names and types fixed in the java classes.
You could generate the classes via a custom class loader, but then you
couldn't refer to the variables except via reflection, which would be
a really dumb and unnecessarily complex way to access config data.
All in all, it's simply a very bad idea: lots and lots of complexity
for practically no gain. Why not use a .properties file?