Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.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!f11g2000yqf.googlegroups.com!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Substitute value in HashMap at runtime Date: Thu, 13 Oct 2011 06:44:36 -0700 (PDT) Organization: http://groups.google.com Lines: 30 Message-ID: References: <70a582b4-956b-4145-9cb8-ba8fbaf751f5@b10g2000vbc.googlegroups.com> NNTP-Posting-Host: 193.0.246.21 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1318513476 17485 127.0.0.1 (13 Oct 2011 13:44:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Oct 2011 13:44:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f11g2000yqf.googlegroups.com; posting-host=193.0.246.21; posting-account=MGO7qgoAAABvyo26eHVDO00044spH-ws User-Agent: G2/1.0 X-HTTP-Via: 1.1 webwasher (Webwasher 6.8.7.9396) X-Google-Web-Client: true X-Google-Header-Order: ASELNKCHRUV X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8761 On Oct 13, 2:18=A0pm, mike wrote: > If I create a HashMap with something like: > > static Map map =3D 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> 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. Cheers robert