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 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> References: <70a582b4-956b-4145-9cb8-ba8fbaf751f5@b10g2000vbc.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: 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 Robert Klemme wrote: > mike wrote: >> If I create a HashMap with something like: >> >> static Map map = new >> HashMap("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 Callable> 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