Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.250.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.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 05:53:48 -0700 (PDT) Organization: http://groups.google.com Lines: 45 Message-ID: <16756426.262.1318510428301.JavaMail.geo-discussion-forums@prgv7> References: <70a582b4-956b-4145-9cb8-ba8fbaf751f5@b10g2000vbc.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1318510547 19415 127.0.0.1 (13 Oct 2011 12:55:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Oct 2011 12:55:47 +0000 (UTC) In-Reply-To: <70a582b4-956b-4145-9cb8-ba8fbaf751f5@b10g2000vbc.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8759 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. Nope. If you do it like that your code will fail to compile (assuming you're referring to 'java.util.HashMap'). Put together a Simple Self-Contained Compilable Example (SSCCE) per http://sscce.org/ Seriously. Do it. Even if you use a correct constructor, if 'MyPreferences.getVariableValue()' is not of type 'String' you have a problem: public class Foo { static Map map = new HashMap<>(); static { map.put( "variable", MyPreferences.getVariableValue() ); } } The type of the entry must match the type of the target. BTW, I assume that 'getVariableValue()' is a static member of 'MyPreferences', given that you named the latter as a type and not a variable. > How can I make my MyPreferences.getVariableValue() be evaluated at > runtime? Any example? Use the expression 'MyPreferences.getVariableValue()'. Let's see that SSCCE in your next post, otherwise there's not much point in continuing, is there? We need full data to understand what you aim to accomplish, and you need full data for any answer to make any sense. SSCCE. http://sscce.org/ -- Lew