Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@jakarta.apache.org Received: (qmail 39632 invoked by uid 500); 29 Sep 2001 02:15:09 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: ant-user@jakarta.apache.org Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 39622 invoked from network); 29 Sep 2001 02:15:08 -0000 To: ant-user@jakarta.apache.org From: hack@socket.net Subject: Re: static final string. Date: Sat, 29 Sep 2001 02:04:00 GMT X-Mailer: Endymion MailMan Standard Edition v3.0.22 Message-ID: <100172899501@socket.net> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N The simplest solution seems to be public static final String mesg = new String( "hello" ); This will not have a value at compile time, and so the String will not be inlined. At 05:30 PM 9/28/2001 +1000, you wrote: >On Fri, 28 Sep 2001 16:17, Tarun Garg wrote: >> public static final String mesg="hello"; >> >> Now class B uses this string for some purpose of its own. >> Lets say it just prints the message. >> class B { >> public static void main(String args[]) >> { >> System.out.println(A.mesg); >> } >> } > >Theres no clean way to do it as it will get inlined in other class. You could >wrap the constant in another object (because the other object wont be >inlined). You could also put in ugly hacks like one of > >class B >{ > private static Class CLASS_HACK_REF = A.class; >} > >or perhaps make it runtime final like > >class A >{ > public static final String mesg = > System.getProperty( "some.key.that.not.exist", "hello" ); >} > >or just do clean builds all the times when you notice such changes. > >-- >Cheers, > >Pete > >---------------------------------------------------------------- >Fools ignore complexity. Pragmatists suffer it. >Some can avoid it. Geniuses remove it. >-- Perlis's Programming Proverb #58, SIGPLAN Notices, Sept. 1982 >----------------------------------------------------------------