Jesper Sahner said:
As I have described the task is somewhat similar to a database-lookup.
It is true that a variable is just a reference to an object or a
primitive type. However it is important that these variables have
names corresponding to the header-information.
Why do you need to use a variable? Why can't you attach that name to the
value using an associative collection (i.e. a Map)?
If the header states,
that the file to be read contains two variables 'var1' and 'var2' of
type 'double' and 'int' then it is important that they are given the
right names 'var1' and 'var2' when read from the file, because
typically the code following the read depends on the right names -
like a database-lookup.
Code cannot use a runtime-defined variable name, as the compiler cannot
compile that (it cannot reference what doesn't exist). It can however, use
a fixed variable to hold the name of another variable, and look up its
value in a Map (and store that value in another fixed variable).
Then again, if what you're doing is like a database lookup, why not use a
database? If it is just for configuration, use a Properties object
(similar to a Map<String,String>, but with load/store capabilities). If it
is more complex, you often want to store business data, and then a
database is most likely the best choice.
So regardless of what you do: make sure your design is right. If you
cannot give a good reason for each design choice, nor explain why it is
better than the alternatives, you've made the wrong choice.