Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8764

Re: Substitute value in HashMap at runtime

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Substitute value in HashMap at runtime
Date Thu, 13 Oct 2011 10:12:46 -0700 (PDT)
Organization http://groups.google.com
Lines 32
Message-ID <98951.924.1318525966990.JavaMail.geo-discussion-forums@prds34> (permalink)
References <70a582b4-956b-4145-9cb8-ba8fbaf751f5@b10g2000vbc.googlegroups.com> <c2bb16de-3ffc-4701-9aa0-1f8f5451908a@f11g2000yqf.googlegroups.com>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 2620:0:1000:437c:224:d7ff:fe69:5838
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1318525967 18447 127.0.0.1 (13 Oct 2011 17:12:47 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Thu, 13 Oct 2011 17:12:47 +0000 (UTC)
In-Reply-To <c2bb16de-3ffc-4701-9aa0-1f8f5451908a@f11g2000yqf.googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:437c:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8764

Show key headers only | View raw


Robert Klemme wrote:
> 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.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Substitute value in HashMap at runtime mike <mikaelpetterson@hotmail.com> - 2011-10-13 05:18 -0700
  Re: Substitute value in HashMap at runtime Lew <lewbloch@gmail.com> - 2011-10-13 05:53 -0700
  Re: Substitute value in HashMap at runtime Robert Klemme <shortcutter@googlemail.com> - 2011-10-13 06:44 -0700
    Re: Substitute value in HashMap at runtime Lew <lewbloch@gmail.com> - 2011-10-13 10:12 -0700
      Re: Substitute value in HashMap at runtime mike <mikaelpetterson@hotmail.com> - 2011-10-14 06:36 -0700
        Re: Substitute value in HashMap at runtime mike <mikaelpetterson@hotmail.com> - 2011-10-14 06:54 -0700
          Re: Substitute value in HashMap at runtime markspace <-@.> - 2011-10-14 08:13 -0700
  Re: Substitute value in HashMap at runtime Roedy Green <see_website@mindprod.com.invalid> - 2011-10-14 09:40 -0700

csiph-web