mike wrote:
If I create a HashMap with something like:
static Map<String,String> map = new
HashMap<String,String>("variable",MyPreferences.getVariableValue());
If I do it like this I guess that MyPreferences.getVariableValue()
will not be substituted but be the "plain" string.
How can I make my MyPreferences.getVariableValue() be evaluated at
runtime? Any example?
One possible way is to change your Map to Map<String,
Callable<String>> and invoke call() at runtime.
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Callable.html
Of course you then need to provide a proper implementation. :-)
Btw, does your Map contain more entries? If not, it's completely
superfluous.
If you define the Map as static you also need to be aware of
concurrency issues if your application will ever access this from
multiple threads.
It doesn't even have to be multiple threads. Multiple instances in the same thread can clobber a static structure if careless. They just take turns messing each other up.